CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

adc problem in PIC24FJ64GB002

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Shristi



Joined: 27 Nov 2010
Posts: 2

View user's profile Send private message

adc problem in PIC24FJ64GB002
PostPosted: Sat Nov 27, 2010 6:44 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Nov 28, 2010 5:54 am     Reply with quote

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

View user's profile Send private message

Didn't work
PostPosted: Mon Nov 29, 2010 8:02 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 30, 2010 12:20 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group