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 support@ccsinfo.com

ADC on PIC24HJ128GP204

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



Joined: 05 Aug 2014
Posts: 21

View user's profile Send private message

ADC on PIC24HJ128GP204
PostPosted: Wed May 17, 2017 8:41 am     Reply with quote

Hi, I'm looking for some help on the ADC of the PIC indicated.
I'm using compiler version 4.116 and accessing the ADC on PIC24HJ128GP204.
The code shown correctly sets up AN0 but as soon as I try any of the other ports Like AN5 or AN6 the result is just noise or 000.
I have simulated the code and see that AD1CHS0 address 328 does not seem to be set up correctly for AN5 or 6.
Is there something I'm missing when setting up the higher Analogue inputs or is this a compiler bug? i.e. Do I have to upgrade?
This chip has a number of S&H Opamps but I'm trying to use only channel 0 and individually accessing the analogue inputs.
I am getting a warning in the Simulator ADC-W0016: Minimum Tad time is 75 ns, it is 32 ns
But no matter how I adjust the ADC clock I can't get rid of the warning.
Any ideas that don't mean a upgrade will be greatly appreciated

Code:
void main()
{
setup_spi( FALSE );
setup_spi2( FALSE );
setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|sAN5|sAN6|sAN7|sAN8|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2 | ADC_TAD_MUL_16);

//LCDFirstwrite();


   setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);
   CNT800=0;


   While(1)
   {
      output_low(PWM1H);
      output_high(PWM1L);
      delay_us(DELAY);
      output_high(PWM1H);
      output_low(PWM1L);
      delay_us(DELAY);
      CNT800++;
      If (CNT800==800)
         {
         CNT800=0;
         set_adc_channel(sAN0);
         delay_us(10);
         data=read_adc();
       set_adc_channel(sAN6);
         delay_us(10);
         data1=read_adc();
      set_adc_channel(sAN5);
         delay_us(10);
         data2=read_adc();
         lcd_gotoxy(1,4);
        printf(lcd_putc,"%04Lx",data);
        lcd_putc(" ");
        printf(lcd_putc,"%04Lx",data1);
        lcd_putc(" ");
        printf(lcd_putc,"%04Lx",data2);
      test=input_state(RL1);
      output_bit(RL1,!test);

         }
     
   }
}

_________________
Neville
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed May 17, 2017 8:56 am     Reply with quote

set_adc_channel, takes a channel number.

So set_adc_channel(0); or set_adc_channel(1) etc.. Not a ADC multiplexer define. What is happening is you are selecting the wrong channel because you are using the wrong value on the select....
Nevillestone



Joined: 05 Aug 2014
Posts: 21

View user's profile Send private message

PostPosted: Wed May 17, 2017 9:27 am     Reply with quote

Thanks, that does work. I'll define some names.
_________________
Neville
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed May 17, 2017 11:23 am     Reply with quote

As a further comment, you do not need the delay between selection and sampling.

On most more basic PIC's you do. This is to allow time for the ADC to actually acquire the signal. However on more sophisticated ADC's like this one, it can be programmed into the setup:

setup_adc(ADC_CLOCK_DIV_2 | ADC_TAD_MUL_16);

The second value here, is how long it'll wait to acquire automatically. So 16 cycles of the ADC clock.

Now I've seen the simulators give incorrect warnings about the Tad. However we can't tell what your actual time is, since you don't post your clock frequency, and/or how the PLL is configured, or whether you are running in 10/12bit mode?.

Worth perhaps saying that unlike the more basic chips on the PIC24's and 33's, you can use ADC_CLOCK_INTERNAL. This runs at about half the maximum allowed for this chip. The time the simulator is quoting is wrong. The minimum Tad specified is 117.5nSec for 12bit mode or 76nSec for 10bit mode. Using the clock from the Fosc, only becomes necessary to get the fastest possible conversion.
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