View previous topic :: View next topic |
Author |
Message |
torlaktr
Joined: 17 Mar 2016 Posts: 10
|
dsPIC30f2020 Adc problem |
Posted: Fri Dec 23, 2016 9:57 am |
|
|
Hello guys
30f2020 adc not working please help me ! Where is the problem ?
My code :
Code: |
#include<30F2020.h>
#device ADC=10
#device *=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOWRTB //Boot block not write protected
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES FRC_PLL //Internal Fast RC oscillator with PLL
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES FRANGE_LOW //Frequency Range for FRC 14.55MHz
#FUSES NOOSCIO //OSC2 is clock output
#FUSES NOPR //Primary oscillaotr disabled
#FUSES NOWINDIS //Watch Dog Timer in Window mode
#FUSES WPRES32 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS1 //Watch Dog Timer PostScalar 1:32768
#FUSES PUT2 //Power On Reset Timer value 128ms
#FUSES NODEBUG //No Debug mode for ICD
#FUSES ICSP1 //ICD uses PGC1/PGD1 pins
#use delay(clock=58200000) // =14.55MHZ *4 (interne rc oscillator
#include <30F2020LCD.c>
int16 amper = 0;
// ADC DEĞİŞKENLER
int16 hamvolt = 0 ;
int16 ana = 0 ;
int16 volt = 0 ;
int8 dsay = 0 ;
int8 mvolt = 0 ;
int16 hamakim = 0 ;
int16 anaakim = 0 ;
int16 akim = 0 ;
// ADC DEĞİŞKENLER
void main()
{
setup_adc(ADC_CLOCK_DIV_32);
SETUP_ADC_PORTS(sAN0|VSS_VDD);
set_tris_a(0b0);
set_tris_b(0b00000010);
set_tris_d(0b0);
set_tris_e(0b00000000);
set_tris_f(0b000);
delay_ms(500);
basla:
set_adc_channel(1);
delay_ms(5);
hamakim = read_adc();
lcd_gotoxy(1, 3);
printf(lcd_putc,"AMP = %04lu ",hamakim,);
goto basla;
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Dec 23, 2016 10:07 am |
|
|
You have only fed AN0 to the multiplexer. ADC channel 0, not 1, on pin B0, which you then have set as an output. ADC 'channel numbers' are the ANx number. If you want to look at AN1, this needs to be selected in the multiplexer setup (sAN1).
Pleas learn to use the code buttons. |
|
|
torlaktr
Joined: 17 Mar 2016 Posts: 10
|
|
Posted: Fri Dec 23, 2016 10:09 am |
|
|
Ttelmah wrote: | You have only fed AN0 to the multiplexer. ADC channel 0, not 1, on pin B0, which you then have set as an output. ADC 'channel numbers' are the ANx number. If you want to look at AN1, this needs to be selected in the multiplexer setup (sAN1).
Please learn to use the code buttons. |
Ttelmah thank you.
But I changed set_adc_channel(san1); but no measurement ?
Where can the problem be?
Very important to me please.... :( |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Dec 23, 2016 11:10 am |
|
|
No.
SETUP_ADC_PORTS(sAN1|VSS_VDD);
Note the '1'.
Is what sets up the multiplexer.
Then
set_adc_channel(1);
is correct to select this input.
The point is that 'channel' '1', is sAN1. |
|
|
torlaktr
Joined: 17 Mar 2016 Posts: 10
|
|
Posted: Fri Dec 23, 2016 11:20 am |
|
|
Ttelmah wrote: | No.
SETUP_ADC_PORTS(sAN1|VSS_VDD);
Note the '1'.
Is what sets up the multiplexer.
Then
set_adc_channel(1);
is correct to select this input.
The point is that 'channel' '1', is sAN1. |
I do the same, but it does not measure
I do not understand everything is right
9 hours and the result is zero :( :( |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 23, 2016 11:34 am |
|
|
Do you have the AVdd and AVss pins connected to anything ? |
|
|
torlaktr
Joined: 17 Mar 2016 Posts: 10
|
|
Posted: Fri Dec 23, 2016 11:58 am |
|
|
PCM programmer wrote: | Do you have the AVdd and AVss pins connected to anything ? |
Thank you Pcm_programming
Yes, of course but no measurement
I do not understand Why Why Why Why is it not measuring
Avdd +5 avss - (gnd) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 23, 2016 12:41 pm |
|
|
1. Post your current test program.
2. Do you get any text displayed on the LCD ? Post what it displays.
3. Measure the voltage that you have on the analog pin with a scope
or a voltmeter and post it.
4. And, what circuit or device is driving the analog pin ? |
|
|
torlaktr
Joined: 17 Mar 2016 Posts: 10
|
|
Posted: Fri Dec 23, 2016 11:02 pm |
|
|
PCM programmer wrote: | 1. Post your current test program.
2. Do you get any text displayed on the LCD ? Post what it displays.
3. Measure the voltage that you have on the analog pin with a scope
or a voltmeter and post it.
4. And, what circuit or device is driving the analog pin ? |
I removed 30f2020 and connect 30f2010 and measure perfect.
After I connect again 30f2020 no measuring :(
10 new pic, results zero.
How can i turn off the pins comparators ?
4) Adc pins
AN1/CMP1B/CN3/RB1
AN2/CMP1C/CMP2A/CN4/RB2
3) 5 VDC Perfect, I'm measuring with oscilloscope.
2) Yes I see, but not measuring.
// TEST PROGRAM
Code: |
1) #include<30F2020.h>
#device ADC=10
#device *=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOWRTB //Boot block not write protected
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES FRC_PLL //Internal Fast RC oscillator with PLL
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES FRANGE_LOW //Frequency Range for FRC 14.55MHz
#FUSES NOOSCIO //OSC2 is clock output
#FUSES NOPR //Primary oscillaotr disabled
#FUSES NOWINDIS //Watch Dog Timer in Window mode
#FUSES WPRES32 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS1 //Watch Dog Timer PostScalar 1:32768
#FUSES PUT2 //Power On Reset Timer value 128ms
#FUSES NODEBUG //No Debug mode for ICD
#FUSES ICSP1 //ICD uses PGC1/PGD1 pins
//#FUSES HS
#use delay(clock=58200000) // =14.55MHZ *4 (interne rc oscillator
#include <30F2020LCD.c>
int16 amper = 0;
#word PORTB = getenv("SFR:PORTB")
// ADC DEĞİŞKENLER
int16 hamvolt = 0 ;
int16 ana = 0 ;
int16 volt = 0 ;
int8 dsay = 0 ;
int8 mvolt = 0 ;
unsigned int16 hamakim = 0 ;
int16 anaakim = 0 ;
int16 akim = 0 ;
// ADC DEĞİŞKENLER
void main()
{
//PORTB = 0b0000000000000000;//
setup_adc_ports(sAN1 | sAN2, VSS_VDD);
setup_adc(ADC_CLOCK | ADC_TAD_MUL_0);
//output_low(pin_b1);
set_tris_a(0b0);
set_tris_b(0b00000110);
set_tris_d(0b0);
set_tris_e(0b00000000);
set_tris_f(0b000);
lcd_init();// BU KODU YAZMAK MECBURİİİİ
delay_ms(500);
basla:
set_adc_channel(sAN1);
hamakim = read_adc();
delay_us(50);
lcd_gotoxy(1, 3);
printf(lcd_putc,"AMP = %04lu ",hamakim,);
delay_ms(50);
goto basla;
} |
|
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Dec 24, 2016 5:49 am |
|
|
If you look in the header you will find sAN1 is equal to 2 not 1.
For set_adc_channel() the parameter should be 0-7 not sANx.
Also, you MUST have a short delay between set_adc_channel() and read_adc for the ADC acquisition to occur.
Therefore:
Code: | set_adc_channel(1);
delay_us(20);
hamakim = read_adc();
delay_us(50);
|
_________________ Google and Forum Search are some of your best tools!!!! |
|
|
torlaktr
Joined: 17 Mar 2016 Posts: 10
|
|
Posted: Sat Dec 24, 2016 1:02 pm |
|
|
dyeatman wrote: | If you look in the header you will find sAN1 is equal to 2 not 1.
For set_adc_channel() the parameter should be 0-7 not sANx.
Also, you MUST have a short delay between set_adc_channel() and read_adc for the ADC acquisition to occur.
Therefore:
Code: | set_adc_channel(1);
delay_us(20);
hamakim = read_adc();
delay_us(50);
|
|
I did the same again. But it does not measure :( HELP MEEEE :(( |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Dec 24, 2016 4:59 pm |
|
|
Read this thread on the Microchip forum:
http://www.microchip.com/forums/m261838.aspx
It says the dsPIC30F2020 A/D is different than other dsPIC's.
I don't have the PCD compiler, so I can't look at the 30F2020.h file
and see how to configure the A/D, or if it's even supported correctly
by CCS. I can't really help you anymore.
If you search Google with this search string, you'll find there are lots
of people who have problems using the special A/D on this PIC.
Quote: | site:microchip.com/forums dspic30f2020 ADC OR A/D |
|
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Dec 24, 2016 6:24 pm |
|
|
Based on this comment:
Quote: | I removed 30f2020 and connect 30f2010 and measure perfect. |
It would appear PCM is likely correct.
I am on travel right now and also cannot test this but I can test it on Monday.
Please post the latest version of your code. If I have time I'll check the compiled code against the datasheet. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
torlaktr
Joined: 17 Mar 2016 Posts: 10
|
|
Posted: Sun Dec 25, 2016 3:01 am |
|
|
dyeatman wrote: | Based on this comment:
Quote: | I removed 30f2020 and connect 30f2010 and measure perfect. |
It would appear PCM is likely correct.
I am on travel right now and also cannot test this but I can test it on Monday.
Please post the latest version of your code. If I have time I'll check the compiled code against the datasheet. |
no measuring :((
Code: |
#include<30F2020.h>
#device ADC=10
#device *=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOWRTB //Boot block not write protected
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES FRC_PLL //Internal Fast RC oscillator with PLL
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES FRANGE_LOW //Frequency Range for FRC 14.55MHz
#FUSES OSCIO //OSC2 is clock output
#FUSES NOPR //Primary oscillaotr disabled
#FUSES NOWINDIS //Watch Dog Timer in Window mode
#FUSES WPRES32 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS1 //Watch Dog Timer PostScalar 1:32768
#FUSES PUT2 //Power On Reset Timer value 128ms
#FUSES NODEBUG //No Debug mode for ICD
#FUSES ICSP1 //ICD uses PGC1/PGD1 pins
#use delay(clock=58200000) // =14.55MHZ *4 (interne rc oscillator
#include <30F2020LCD.c>
#word ADCBUF7 = getenv("SFR:ADCBUF7")
#word ADPCFG= getenv("SFR:ADPCFG")
#word ADSTAT= getenv("SFR:ADSTAT")
int16 hamakim = 0 ;
int16 hamakima = 0 ;
void main()
{
SETUP_ADC_PORTS(sAN6);
SETUP_ADC(ADC_CLOCK_DIV_32|ADC_TAD_MUL_16);
set_tris_a(0b0);
set_tris_b(0b10000000);
set_tris_d(0b0);
set_tris_e(0b00000000);
set_tris_f(0b000);
lcd_init();// BU KODU YAZMAK MECBURİİİİ
delay_ms(500);
basla:
set_adc_channel(san6);
delay_us(50);
hamakim = read_adc();
delay_us(50);
lcd_gotoxy(1, 4);
printf(lcd_putc,"AMPd = %04lu ",hamakim,);
goto basla;
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Sun Dec 25, 2016 6:04 am |
|
|
While I don't use that PIC..
...have you tested it with a '1Hz LED ' program to confirm the PIC hardware is operational ?
what are the differences in the 2 PICs you use? Are ALL the registers the same?, pintout ,??? Are the 2 PIC headers identical ? If not what is different?
is the PCB you're using the same one for both PICs? or a separate one? If separate, maybe the ADC pin is shorted to ground?
Jay |
|
|
|