jaka
Joined: 04 May 2014 Posts: 42 Location: Finland
|
| ADC2 (or ADCC) operation with K83 |
Posted: Thu Feb 26, 2026 8:38 am |
|
|
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
|
|
Posted: Sun Mar 01, 2026 7:36 am |
|
|
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. |
|