Problem with Nick12AB serial Bargraph in 10 bit ADC mode

hamtech

Member
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.
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
 

Rick100

Senior Member
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.
If it's working with an 8 bit number and you want to use a 10 bit number, then you can divide the 10 bit number by 4 to shift it 2 bits to the right, before calling the original 8 bit routine.
 

srnet

Senior Member
I dont believe so, as it works with that value on another project which uses parallel lcds though. If i make it 1023 it still gives the same effect..
Hamtech
I did not look at the code specifically, but as you said for 8 bit mode you divided by 255, then for 10 bit mode 1023 makes sense .........
 

hamtech

Member
Rick

Thanks but this should work, but as I don't understand quite how the code does its stuff, I am hoping Nick12AB will come to the rescue. Your solution is a workaround but does not fix the problem. But I will keep that in mind if I can't resolve it.

The 10 bit number I need for doing the headingsmore accurately as the difference between the ADC number for say east in 8 bits is 255/4 and in 10 bit is 1023/4 much bigger numbers to play with.

What perhaps I shoud explain, is that the beam travels from N->E-S->W->N and back through west,south east and back to north. In other words it does not turn through 360 degrees as the cables would wrap them selves aroundf the mast. There are physical stoppers to prevent that.

The voltage on the pot varies between 5v N= north to 0v = north going through West to South then East back to North.


Hope that clarifies things .
 

hamtech

Member
SRnet

In my digital voter project the code for which is posted in finished projects, it uses the same bargraph routine and a divisor of 1024 , the only difference is that it is for a parallel lcd and Nicks codes differs from the serial to parallel version. One obvious answer is to use a parallel LCD again, but I have got a 4x20 LCD with a serial input that I want to use as speed is not a factor.
 

hamtech

Member
All,

Thank you for your help, I have found the problem. My subroutine to extract Hundreds, Tens and Units from the 10bit ADC value was modifying w1 wrongly and needed an extra word variable.

Thanks again to those who assisted me.
 
Top