I'm building a combined speed controller, driver display and datalogger for an electric car using a 40x2 picaxe chip as the processor. The 40x2 provides a PWM output to the speed controller and adjusts it so that a predefined current set on a rotary pot is maintained. It also sends raw data from various sensors to an Openlog microSD datalogger. All of the above it seems to be doing very well, the problems arise when I try to display information on the AXE033 LCD for the driver.
There are two lines of data I wish to display, one is the individual voltage of two batteries and current draw; the other is motor temperature and PWM duty percentage. I can display the voltages and current on either or both lines without fault, but as soon as I try to display temp and PWM duty on either line all I get is odd characters and erratic behaviour that also interfere with the other line of the display. I've tried using word variables with no success, various values of pulldown resistors on the output pin, both picaxe and LCD are powered by the same regulated 5v supply so I'm now at a loss.
I'd be grateful if someone could have a look at the code, maybe I've done something stupid somewhere! At the moment I've got the voltage and current line displaying on the top with my other options commented out and this works, but as soon as I make the code active that sends variables 28 and 30 to the bottom line it just makes a mess.
There are two lines of data I wish to display, one is the individual voltage of two batteries and current draw; the other is motor temperature and PWM duty percentage. I can display the voltages and current on either or both lines without fault, but as soon as I try to display temp and PWM duty on either line all I get is odd characters and erratic behaviour that also interfere with the other line of the display. I've tried using word variables with no success, various values of pulldown resistors on the output pin, both picaxe and LCD are powered by the same regulated 5v supply so I'm now at a loss.
I'd be grateful if someone could have a look at the code, maybe I've done something stupid somewhere! At the moment I've got the voltage and current line displaying on the top with my other options commented out and this works, but as soon as I make the code active that sends variables 28 and 30 to the bottom line it just makes a mess.
Code:
'THSYE Picaxe based speed controller, G C-S 13/02/10
'40x2 processor, current limit set by pot, button to initiate.
'Serial output to LCD, serial output to Openlog datalogger
setfreq em16 'processor speed
settimer t1s_16 'sets increments for timestamp to be recorded to datalogger
serout B.7,N2400_16,(254,1) 'clear LCD display
pause 10000 'Allows time for Openlog datalogger to initiate
w9=0 'variable for pwm duty set to zero at startup
b27=0 'logging loop counter set to zero
input d.0 'pin for "go" button set as input
goto startup
startup:
b27=b27+1 'periodical logging loop
if b27=200 then
goto serial1
else endif
if b26>70 then 'check motor temp is OK
goto limphome 'if motor hot goes to low power setting
else endif
if pind.0=1 then 'check if "go" button is pressed
goto minpow 'if not pressed go to power off routine
else
goto currcontrol 'if pressed will go to control loop
endif
limphome: 'allows car to return to pits at low power setting
if pind.0=1 then 'check if "go" button is pressed
goto minpow
else
w9=200 'set to low power
pwmout C.1 , 249, w9
endif
currcontrol:
readadc10 0,w0 'toroidal current sensor
readadc10 1,w1 'current limiting rotary pot
w4=w1/13+580 'scale pot reading to match current sensor range
if w0>w4 then powdown 'decide which way to adjust motor power to reach target current
if w0<w4 then powup
powdown:
if w9<25 then minpow 'prevents w9 overflowing back
w9=w9-3 'increments w9 downwards to match target current
pwmout C.1 , 249, w9 'sets pwm duty
goto startup
powup:
if w9>975 then maxpow 'prevents w9 overflowing above 1000
w9=w9+3 'increments w9 upwards to match target current
pwmout C.1 , 249, w9 'sets pwm duty
goto startup
maxpow:
w9=1000 'puts pwm to maximum setting
pwmout C.1 , 249, w9
goto startup
minpow:
w9=0 'puts pwm to minimum setting
pwmout C.1 , 249, w9
goto startup
serial1:
readadc10 0,w0 'toroidal current sensor, re-reads this sensor
readadc10 2,w2 'Battery A potential divider
readadc10 3,w3 'Battery B potential divider
readadc10 5,w5 'Motor temperature thermistor
'readadc10 6,w6 'CVT slider pot
b20=w0-507*10/51 'calc current digits
b21=w0-507*10//51*10/51 'calc current decimal
b22=w2/76 'calc Bat A voltage digits
b23=w2//76*10/76 'calc Bat A voltage decimal
b24=w3/76 'calc Bat B voltage digits
b25=w3//76*10/76 'calc Bat B voltage decimal
b30=w5-280/8 'calc motor temp
b28=w9/10 'calc % pwm setting
'temp and power settings for top line of lcd
'pause 50
'Serout B.7,N2400_16,(254,128,#b30," ")
'pause 50
'Serout B.7,N2400_16,(254,134,#b28," ")
'pause 50
'battery voltages and current for top line of lcd
pause 50
serout B.7,N2400_16,(254,128,#b22,".",#b23," ")
pause 50
serout B.7,N2400_16,(254,134,#b20,".",#b21," ")
pause 50
serout B.7,N2400_16,(254,140,#b24,".",#b25," ")
'temp and power settings for bottom line of lcd
'pause 50
'Serout B.7,N2400_16,(254,192,#b30," ")
'pause 50
'serout B.7,N2400_16,(254,198,#b28," ")
'battery voltages and current for bottom line of lcd
'pause 50
'serout B.7,N2400_16,(254,192,#b22,".",#b23," ")
'pause 50
'serout B.7,N2400_16,(254,198,#B20,".",#B21," ")
'pause 50
'serout B.7,N2400_16,(254,204,#b24,".",#b25," ")
high d.4 'set pin high prior to sending raw data to openlog
pause 10
serout d.4,t9600_16,(#w0,",",#w1,",",#w2,",",#w3,",",#w4,",",#w5,",",#w6,",",#w9,",",#timer,cr)
b27=0
goto startup