afb
Member
In my 08M2 project I'm continually measuring the battery supply voltage and also reading a 5k pot (connected across the supply rails - wiper to C.4) which is part of the main function of the program. I found the measured supply voltage reading varied as I adjusted the pot - the error coming in after the pot got somewhere over half setting. I wrote some simple test programs to explore the phenomenon and they are appended at the end of this post - rem out each section in turn to see the story develop. But first here is a picture of the terminal readout when adjusting the pot running the "case 2" code snippet. It shows the pot setting (0-255) followed by the measured supply voltage, in this case 5v (value 50 returned = 5.0v) As you will see with the pot at full rotation the reported supply voltage has dropped to 3.0v !!
As you will see I found a workaround - the far more extensive project code requires to run at 32Mhz
As you will see I found a workaround - the far more extensive project code requires to run at 32Mhz
Code:
'08M2 - measuring supply voltage
'5k pot across supply, wiper to leg 3 (C.4)
#rem
'------------------------------------------------------------------------
'1st case - works ok, returns 50 (5.0v) regardless of pot setting
'------------------------------------------------------------------------
setfreq m32
do
calibadc10 w1
w1 = 10500/w1
sertxd(#w1,13,10)
pause 5000
loop
#endrem
'------------------------------------------------------------------------
'2nd case - introduce readadc and now an error in voltage is returned
'as the the pot is adjusted (see attached image of terminal readout)
'------------------------------------------------------------------------
setfreq m32
do
readadc C.4,b0
calibadc10 w1
w1 = 10500/w1
sertxd(#w0," ",#w1,13,10)
pause 5000
loop
#rem
'------------------------------------------------------------------------
'3rd case - reduce clock speed - works correctly
'------------------------------------------------------------------------
setfreq m4
do
readadc C.4,b0
calibadc10 w1
w1 = 10500/w1
sertxd(#b0," ",#w1,13,10)
pause 500
loop
'------------------------------------------------------------------------
'4th case - workaround - just the calibadc10 command was sensitive
'------------------------------------------------------------------------
do
setfreq m4
calibadc10 w1
setfreq m32
readadc C.4,b0
w1 = 10500/w1
sertxd(#b0," ",#w1,13,10)
pause 5000
loop
#endrem