Author Topic: PIC18F46K42 xpress EVAL Board - ADC program  (Read 987 times)

0 Members and 1 Guest are viewing this topic.

Offline arulTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: in
PIC18F46K42 xpress EVAL Board - ADC program
« on: December 02, 2018, 05:10:08 pm »
Hi,

  I have a PIC18F46K42 xpress evaluation board. Now I am developing one of the ADC program using MPLAB Xpress PIC18F46K42 evaluation board on MPLAB CLOUD IDE. I make one of the simple circuit for that program using variable power supply, resistor. I am varying the power source, but that ADC result register value does not change, only shown 0x00 (i got that value 0x00, in debug mode). I have attached my code and circuit.

Please let me know, what is going wrong.....


void main()
{
int RH, RL;

ADCON0bits.FM = 1;
ADCON0bits.CS = 1;
ADPCH = 0b00011100;   //RD4 is analog input
TRISDbits.TRISD4 = 1;
ANSELDbits.ADSELD4 = 1;
ADCON0bits.ON = 1;

   while(1)
   {
   ADCON0bits.GO = 1;
   while(ADCON0bits.GO);
   RH = ADRESH;
   RL = ADRESL;
   }
}
 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1611
  • Country: gb
Re: PIC18F46K42 xpress EVAL Board - ADC program
« Reply #1 on: December 02, 2018, 09:04:52 pm »
In order to check if your code is enough people would have to find the datasheet, go to the ADC section, as well as the GPIO section and check that all the required config registers are correct.  Whilst I'm sure other will do that its a fair bit of work.  So perhaps you could use the mplab xpress code configurator, then view the generated code for the ADC? (you'll probably have to look at the IO code too).

That should show you all the registers relating to the ADC, and you can then use their values along with the datasheet to see what the "configurator" has done, and why it has done it.

Also, you haven't provided your entire code.  How are you reading RH and RL?  From debugger? GPIO port? serial?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf