Problem with ADCON3 Register and ADC

General discussion on mikroC for dsPIC30/33 and PIC24.
Post Reply
Author
Message
skrasms
Posts: 33
Joined: 20 Feb 2008 20:34

Problem with ADCON3 Register and ADC

#1 Post by skrasms » 11 Oct 2008 07:54

I am using a dsPIC30F4013 running at 80Mhz (10Mhz crystal * 8 PLL), ie 20 MIPS.

According to the datasheet, in calculating ADCS<5:0> the formula is 2*Tad/Tcy - 1.

For a Tad of 668ns, that gives:

2*(668e-9)/(5e-8) - 1 = 26.72

To ensure it is long enough, I chose 27. That caused my code to get stuck in an endless loop. In fact, any value greater than 16 causes my program not to work, while any value 16 or less executes.

My main code looks like this:

Code: Select all

  ADCON1 = 0;
  ADCSSL = 0;
  ADCON3 = 0x1010;  
  ADCON2 = 0x6000;  //B0 and B1 for Vref+ and Vref-
  ADCON1.F15 = 1;

  Delay_us(40);

  ADCHS = 3;
  ADCON1.F1 = 1;
  Delay_us(1);
  ADCON1.F1 = 0;
  while(ADCON1.F0==0){}
  lastval = ADCBUF0;
If ADCS is set to be greater than 16, ADCON1.F0 never becomes set to 1. 16 or less and the program executes but has accuracy problems. Before I mess more with the analog side, what am I doing incorrectly with ADCON3?

Post Reply

Return to “mikroC for dsPIC30/33 and PIC24 General”