I used the simplest setup and code I could think of to learn how to use ReadAD10.
A 10K pot is connected to an analog input, is slowly rotated from 0 to +5V, and the
value returned from the ADC is shown on an LCD. The results are puzzling. See comments
in the code to see the results when the value is not dimensioned, and when it is
dimensioned as a byte, or as a word. Any help appreciated.
'Observe output of ReadAD10 as linear potentiometer turned from 0 to 5V.
'HARDWARE:
' 2 x 16 LCD, 2-wire mode using MYKE PREDKO's LCD interface
' based on 74LS174.
' GP0 to Data on LCD interface
' GP1 to Clock on LCD interface
' AN2 to 10K pot wiper, other 2 leads to +5V & GND
#chip 12F683,8 'PIC12F683 running at 8 MHz
#config mclr=on 'reset handled manually
#config osc=int 'use internal clock
'relevant constants for 2-wire mode-----------------------------------
#define LCD_IO 2 '2-wire mode
#define LCD_DB GPIO.0 'shift register data on GP0, pin 7
#define LCD_CB GPIO.1 'shift register clock on GP1, pin 6
'Analog setup---------------------------------------------------------
#define poten AN2 'output from pot on AN2, pin 5
dir AN2 in 'make AN2 an input
'Main program---------------------------------------------------------
'Run program with value undimensioned, then dimensioned as byte,
'then as word.
'if value not dimensioned, as pot is turned from 0 to 5V, value returned
'is 0 - 255 FOUR TIMES with value 255 seen at 1.25, 2.5,3.75, and 5V.
'dim value as byte 'gives same result as not dimensioning
'dim value as word 'if use this,
' as pot is turned from 0 to 5V, value
' returned is 0 - 511 (0 - 2.5V),then
' abruptly jumps to 65024. Values then
' returned are 65024 - 65535 (2.5 - 5V).
do
Locate 0,0 : Print "Current value:"
value = ReadAD10(poten)
Locate 1,0 : Print value
wait 250 ms
CLS 'refresh display
loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I cannot see an issue. This should work when you define 'value' as a word. Alsp, works on test here on a larger device.
Please confirm your version of compiler. I just reviewed the source code - I cannot see any duplication uses of 'value' but I would recommend using 'ug_value' to ensure your 'u'ser 'g'lobals do not clash with the internal reserved variables. Just a thought.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Jack - to further help. I have just reviewed the code in the debugger. The variable is correct in memory. When I change the POT the memory at location relates to the correct POT value.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Anobium for your help. Your initial response prompted me to swap out my 12F683 for a new one; then it worked. I must have somehow damaged the original chip.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Anobium for your help. Your initial response prompted me to swap out my 12F683 for a new one; then it worked. I must have somehow damaged the original chip.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I cannot see an issue. This should work when you define 'value' as a word. Alsp, works on test here on a larger device.
Please confirm your version of compiler. I just reviewed the source code - I cannot see any duplication uses of 'value' but I would recommend using 'ug_value' to ensure your 'u'ser 'g'lobals do not clash with the internal reserved variables. Just a thought.
@Jack - to further help. I have just reviewed the code in the debugger. The variable is correct in memory. When I change the POT the memory at location relates to the correct POT value.
Thanks Anobium for your help. Your initial response prompted me to swap out my 12F683 for a new one; then it worked. I must have somehow damaged the original chip.
Thanks Anobium for your help. Your initial response prompted me to swap out my 12F683 for a new one; then it worked. I must have somehow damaged the original chip.