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

ADC2 (or ADCC) operation with K83

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



Joined: 04 May 2014
Posts: 42
Location: Finland

View user's profile Send private message

ADC2 (or ADCC) operation with K83
PostPosted: Thu Feb 26, 2026 8:38 am     Reply with quote

I am trying to use the ADC with computation on PIC18F26K83. My compiler version is 5.116. I have used it on legacy mode for some years and working OK, but I wanted to have some averaging to get rid of small noise in results.

I have tried to set it up on burst average mode, to average 4 samples automatically
Code:
setup_adc(ADC_BURST_AVERAGE_MODE | ADC_CLOCK_DIV_16 | ADC_TAD_MUL_64, 2, 4);


The conversions are started with command
Code:
read_adc(ADC_START_ONLY);



Then the filtered result should be possible to read like this:
Code:
fresh_adc_readout = adc_read(ADC_FILTER);


However, I am getting almost static readings. But if I try to read with the legacy command
Code:
fresh_adc_readout = read_adc(ADC_READ_ONLY);

I am getting the expected result as earlier.

The list file perhaps reveals the problem. This shows the output for three different readout commands. To me it seems that the adc_read() function doesn't read the low byte correctly. The fresh_adc_readout variable is located at 1F1,1F2 accoding to symbol file.

Code:
....................    unsigned int16 fresh_adc_readout;
....................   
....................    if (adc_done()) {
0342E:  MOVLB  3E
03430:  BTFSC  xF8.0
03432:  BRA    3536
....................       fresh_adc_readout = adc_read(ADC_FILTER);       // Read the previous, filtered result
03434:  MOVFFL 3EE7,1F2
0343A:  MOVLB  1
0343C:  MOVFF  EE6,1F1
....................       fresh_adc_readout = read_adc(ADC_READ_ONLY);    // Read the previous ADC result with legacy command
03440:  MOVLB  3E
03442:  BTFSC  xF8.0
03444:  BRA    3442
03446:  MOVFFL 3EF0,1F2
0344C:  MOVFFL 3EEF,1F1
....................       fresh_adc_readout = adc_read(ADC_RESULT);       // Read the previous ADC result with new command
03452:  MOVFFL 3EF0,1F2
03458:  MOVLB  1
0345A:  MOVFF  EEF,1F1


Has someone else used the ADC2 peripheral succesfully? Am I doing something wrong with setting up the peripheral?
Ttelmah



Joined: 11 Mar 2010
Posts: 20040

View user's profile Send private message

PostPosted: Sun Mar 01, 2026 7:36 am     Reply with quote

Have you tried testing for ads_done, before the read?.
How small is the result?. Possibly 1/4 what you expect?. The filter mode
automatically divides by the number of samples. You are specifying to
shift the result 2 places left as well, so 1/4 the normal result.
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