I am working on a project to control my HF Beam antenna with a 14M2. I am trying to display a bar graph of the bearing as well as the bearing itself. I am using Nick12AB's very good serial bar graph routine and it all works fine when I use the ADC in 8 bit mode, i.e. the output is 0-255 , bargraph travels full width of the LCD no probs. However if possible I want to use 10bit resolution for more accurate beam headings.
When I try to use the routine with 10 bit resolution, using readadc10 and adjusting one line in the routine to divide by 1024 instead of 255, I get a funny happening. The ADC output goes as it should from 0-1023 onscreen . However as the bargraph nears full travel of th width , almost a full bargraph, as I continue turning the potentiometer it disappears off the screen and no bargraph (still got the line of dots though). There is obviously some calculation happening incorrectly but I can't see what it is. I have used the routine on a parallel LCD no problem, it is using it as a serial mode doesn't work properly, there is no need for the speed of a parallel LCD as the rotator is SLOW.. I attach the code. Any help gratefully received as I can't continue on developing until I get this problem resolved for 10bit ADC working. Thanks Again Hamtech.
When I try to use the routine with 10 bit resolution, using readadc10 and adjusting one line in the routine to divide by 1024 instead of 255, I get a funny happening. The ADC output goes as it should from 0-1023 onscreen . However as the bargraph nears full travel of th width , almost a full bargraph, as I continue turning the potentiometer it disappears off the screen and no bargraph (still got the line of dots though). There is obviously some calculation happening incorrectly but I can't see what it is. I have used the routine on a parallel LCD no problem, it is using it as a serial mode doesn't work properly, there is no need for the speed of a parallel LCD as the rotator is SLOW.. I attach the code. Any help gratefully received as I can't continue on developing until I get this problem resolved for 10bit ADC working. Thanks Again Hamtech.
Code:
'14m2 test code for aerial rotator project
'using a 4 x20 display i.e. bargraph on line 4 , compass points line 3 and heading display line one
'LCD Command Summary
'Command ' (56) Function 8bit / 2line /5x8
'Command ' (1) Clear Display
'Command ' (2) Cursor Home
'Command ' (7) Character Entry Mode
'Command ' (8) Display Off
'Command ' (12) Display on/ Restore Cursor
'senddata = $0D: Gosub Command ' (13) Blinking Cursor
'senddata = $0E: Gosub Command ' (14) Underline Cursor
'senddata = $10: Gosub Command ' (16) Move Cursor Left
'senddata = $14: Gosub Command ' (20) Move Cursor Right
'senddata = $18: Gosub Command ' (24) Shift Display Left
'senddata = $38: Gosub Command ' (28) Shift Display Right
'senddata = $80: Gosub Command ' (128-147) Line 1 Cursor Position ($80 + 1-19)
'senddata = $C0: Gosub Command ' (192-211) line 2 Cursor Position ($C0 + 1-19)
'senddata = $94: Gosub Command ' (148-167) line 3 Cursor position ($94 + 1-19 continuation of line 1
'senddata = $D4: Gosub Command ' (212-231) line 4 Cursor position ($D4 + 1-19)continuation of line 2
symbol lcdpin = C.2 ' Serial Out to LCD
symbol adcpin = C.4 ' Abnalogue voltage in from variable resistor
symbol readvar = w1 ' Read voltage into 10 bits
symbol length = b5
symbol loopcounter = b6
symbol charactercounter = b7
symbol endposition = b8
symbol heading=w0 ' Beam Heading to display in degrees wordlength variable
' Symbol HTH =b12not used at present
symbol HH= b13
symbol HT=b14
symbol HU=b15
symbol lcdsize = 18
symbol baud = N2400_8
' Initialise the screen
pause 1000 ' let things settle
start:
setfreq m8
dirsC =255
serout lcdpin,baud,(255,0) ' select upper 2 lines
pause 100
Serout lcdpin,baud, (254,1) ' clear upper 2 lines
pause 100
serout lcdpin,baud,(255,1) ' select upper 2 lines
pause 100
Serout lcdpin,baud, (254,1) ' clear upper 2 lines
pause 100
serout lcdpin,baud,(255,0) ' select upper 2 lines
pause 100
Serout lcdpin,baud, (254,128)' start pos line 1
Pause 100
serout lcdpin, N2400_8, (254, 64, 32, 32, 32, 53, 32, 32, 32, 32)
serout lcdpin, N2400_8, (254, 72, 32, 48, 48, 53, 48, 48, 32, 32)
serout lcdpin, N2400_8, (254, 80, 32, 52, 52, 53, 52, 52, 32, 32)
serout lcdpin, N2400_8, (254, 88, 32, 53, 53, 53, 53, 53, 32, 32)
serout lcdpin, N2400_8, (254, 96, 34, 39, 47, 49, 47, 39, 34, 32)
serout lcdpin, N2400_8, (254, 104, 40, 60, 58, 49, 58, 60, 40, 32)
endposition = lcdsize + 193
main:
Serout lcdpin,baud, (254,148,"N E S W N")' start pos line 3
do
readadc10 adcpin,readvar
let heading = readvar ' MAX 1010 ' value of adc 10 bit mode
gosub brg_disp
Serout lcdpin,baud, (254,128,"Heading = ",#HH,#HT,#HU," ",254,endposition, 13,254,212,12)' start pos line 4
' heading at present display ADC output but will become the bearing later.
length = lcdsize * 3 - 1 * readvar / 1024 + 1
serout lcdpin,N2400_8,(254,128,254,endposition,13,254,212,12)
charactercounter = lcdsize
do
dec charactercounter
if length > 3 then
serout lcdpin,N2400_8,(11)
length = length - 3
else
exit
end if
loop
readvar = length + 8
serout lcdpin,N2400_8,(readvar)
looplabel:
if charactercounter > 0 then
serout lcdpin,N2400_8,(8)
dec charactercounter
else
goto main
end if
goto looplabel
loop
brg_disp: ' get values to display as bearing
' let HTH = heading /1000 ' returns quotient
let w1= heading// 1000
let HH= w1 /100 ' returns quotient = hundreds
let b10= w1 //100 ' remainder modulus divide b14 (not displayed)
let HT=b10 /10 ' returns quotient = tens
let HU=b10 //10 ' remainder of modulus divide = units
return