View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 22, 2007 12:50 pm |
|
|
His A/D is not configured for 10-bit mode. The compiler defaults to
8-bit mode.
Here's the code from the .LST file for the posted program
The A/D is configured for left-justified output. Then, only
the MSB of the result is read, from the ADRESH register.
This discards the lower two bits. The posted program
puts this 8-bit result into the LSB of a 16-bit variable.
The code below clears the MSB of the variable.
Code: | ...... value=read_adc();
002F: BSF ADCON0.2
0030: BTFSC ADCON0.2
0031: GOTO 030
0032: MOVF ADRESH,W
0033: CLRF value+1
0034: MOVWF value |
|
|
|
sonicfire
Joined: 11 Feb 2007 Posts: 19 Location: Cedar Rapids
|
|
Posted: Thu Feb 22, 2007 1:05 pm |
|
|
I now understand why the PWM only accepts values from 0 to 19, but I'm not sure why the A/D converter returns a number 0 to 1023. I tried implementing the change with no success. The scope output is unintelligible. I can manually set the A/D value from 0 to 20 and get satisfactory results, but I can't seem to read an input voltage (0 to 5V from a 5K pot) with the same success.
If my A/D converter is defaulting to 8bit read, how can I change it to read 10bits in my C code? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 22, 2007 1:32 pm |
|
|
Quote: | how can I change it to read 10bits in my C code? |
Code: |
#include <16F877.H>
#device adc=10 // Add this line in this exact location.
|
|
|
|
sonicfire
Joined: 11 Feb 2007 Posts: 19 Location: Cedar Rapids
|
|
Posted: Thu Feb 22, 2007 1:33 pm |
|
|
thanks |
|
|
sonicfire
Joined: 11 Feb 2007 Posts: 19 Location: Cedar Rapids
|
|
Posted: Thu Feb 22, 2007 1:40 pm |
|
|
You guys were both dead on! I now understand the scaling factor and that works quite well. The 10bit adc seems to have fixed a lot of problems as well. Thank you. |
|
|
|