View previous topic :: View next topic |
Author |
Message |
Shristi
Joined: 27 Nov 2010 Posts: 2
|
adc problem in PIC24FJ64GB002 |
Posted: Sat Nov 27, 2010 6:44 pm |
|
|
I don't know what's going on. I am trying to read ADC pin from my microcontroller. But it always refers to the voltage at PIN 2 "AN0" even though my C code says to read the voltage at Pin B15 "AN9". If the voltage is at 2 V or less it always shows 255. If ADC is 8 bit and if I increase the voltage then the reading starts to decrease. When I am at 5 V then it goes to 160. If I keep increasing it surely will go down more but I don't want to fry my chip up so I stopped. But this doesn't make any sense. Why is the microcontroller not reading the adc channel 9 at all ? Can anyone help me out on this. Here is my code:
Code: |
#include <24FJ64GB002.h>
#device ADC=8
#fuses HS, PR_PLL, NOWDT, NOPROTECT, NODEBUG, SOSC_IO,ICSP1,OSCIO
//Configure a 20MHz crystal to operate at 48MHz per USB standards
#use delay(clock=20000000)
#include <stdlib.h> // Header needed for some operations
#include <lcd.c>
int8 reading1 = 0;
void main(void)
{
//------------------------Configuration of ADC Ports-------------------------
lcd_init();
delay_ms(1000);
setup_adc( ADC_CLOCK_INTERNAL| ADC_TAD_MUL_0 );
setup_adc_ports( sAN9);
set_adc_channel(9);
delay_ms(1000);
while (true)
{
reading1=read_adc();
printf(lcd_putc,"\fvoltage=%lu\n",reading1);
delay_ms(100);
}
} |
I also tried making my pin B15 input pin but still nothing happened.
Thank You.
Shristi!!! |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Nov 28, 2010 5:54 am |
|
|
According to the PIC24 manual, TAD_MUL = 0 is not recommended. Internal clock is mainly intended
to be used in sleep mode. You may want to start with a slow setting, e.g.:
Code: | setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_16); |
|
|
|
Shristi
Joined: 27 Nov 2010 Posts: 2
|
Didn't work |
Posted: Mon Nov 29, 2010 8:02 pm |
|
|
Hi there, thanks for your reply. I am sorry I didn't reply ahead. I was waiting for email but I never received any even though you replied back.
I tried doing what you said but now I get only 0 as my output from the ADC. Do you have any more idea of what's missing in the code???
Thanks in advance |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Nov 30, 2010 12:20 am |
|
|
I don't have this particular chip. With other PIC24 types, the ADC performs well. Obligate question: What's your compiler version?
Quote: | #include <lcd.c>
...
lcd_init();
| It would be better to test the actual code shown in the post, removing any unnecessary stuff. It's nearly impossible to be aware of all potential side effects. |
|
|
|