Hi all.
I'm attempting to control a sevo motor off the output pins of my 18X chip. The chip is wired to the AXE033 LCD and works perfectly. The servo is connected to it's own 4xAA battery back with the common ground connected to the Picaxe ground. The Picaxe is powered by a mains regulated 5v through a 7805 and transformer.
My problem is that if I use the servo or servopos command -anywhere- in the code, regardless of if I even have the motor connected or not, my Axe033 which is connected via ic2 gets garbled:
It remains garbled like this until new LCD write commands are sent to overwrite the garble, but will quickly return to this state, sometimes not even all at once but gradually with different characters changing.
My code is as follows (lotsa useless garble in there but I wasn't sure if removing anything would be wise xD):
Any suggestions would be great, I'm certain it has nothing to do with my actual servo as disconnecting it makes no difference. Perhaps something to do with ic2 and the servo command? Despite the garble, when I do include the servo commands they do work and the servo moves fine.
I'm attempting to control a sevo motor off the output pins of my 18X chip. The chip is wired to the AXE033 LCD and works perfectly. The servo is connected to it's own 4xAA battery back with the common ground connected to the Picaxe ground. The Picaxe is powered by a mains regulated 5v through a 7805 and transformer.
My problem is that if I use the servo or servopos command -anywhere- in the code, regardless of if I even have the motor connected or not, my Axe033 which is connected via ic2 gets garbled:
It remains garbled like this until new LCD write commands are sent to overwrite the garble, but will quickly return to this state, sometimes not even all at once but gradually with different characters changing.
My code is as follows (lotsa useless garble in there but I wasn't sure if removing anything would be wise xD):
Code:
symbol seconds = b1
symbol mins = b2
symbol hour = b3
symbol day = b4
symbol date = b5
symbol month = b6
symbol year = b7
symbol DS1307 = %11010000 'i2cslow, i2cbyte
symbol AXE033 = %11000110 'i2cslow, i2cbyte
init:
b0=0 'Intially start in display mode 0, saved in register 80
poke 80,b0
'REGISTERS:
' 80 - Current display mode
' 81 - Dosage 1 quanitty
' 82 - Dosage 2 quantity
main:
w1=0
i2cslave DS1307, i2cslow, i2cbyte 'Initialise Axe033 for reading from DS1307 registers
readi2c 0, (seconds,mins,hour,day,date,month,year) 'Reads in the timing data
'Dosage Calculation - Pretty important...right?
{ readadc 1,b0 'Read the current dial setting (pot), range is 0-255
readadc 0, b4 'Read the second potentiometer
'Dosing will occur once a day
'Increments of size: 255/10
b0=b0/10
b4=b4/10
poke 81, b0 'Save the amounts we're dosing to the registers
poke 82, b4 'Decimal accuracy will be clipped by integer division
}
i2cslave AXE033, i2cslow, i2cbyte ' Initialise Axe033 for writing time/date to LCD
''''''''''''''''''''
'MODE 0 DISPLAY TIME
''''''''''''''''''''
{ peek 80,b0
if b0=0 then
writei2c 0,(254,128,255) ' Set the cursor to the very start
pause 10
bcdtoascii seconds, b8,b9 'Converts the bcd into ascii values
bcdtoascii mins, b10,b11
bcdtoascii hour, b12,b13
writei2c 0,(" Time:",b12,b13,":",b10,b11,":",b8,b9,255) 'Write the ascii to the LCD
pause 10 'Pause after every write
writei2c 0,(254,192,255)
pause 10
writei2c 0,(" Dosing ON.",255)
high 5
end if
}
''''''''''''''''''''''
'MODE 1 DISPLAY DOSAGE
''''''''''''''''''''''
peek 80, b0
{ if b0=1 then
peek 81,b0
peek 82, b4
bintoascii b0,b12,b1,b2
bintoascii b4,b12,b5,b6
writei2c 0,(254,128,255)
writei2c 0,("Dose 1:",b1,b2," ml/day",255)
pause 10
writei2c 0,(254,192,255) 'Set the cursor to the second line
writei2c 0,("Dose 2:",b5,b6," ml/day",255)
pause 10
low 5
end if
}
''''''''''''''''''''''
'MODE 2 FORCE DOSAGE
''''''''''''''''''''''
peek 80, b0
{ if b0=2 then
writei2c 0,(254,128,255)
writei2c 0,("Force dose:",255)
pause 10
writei2c 0,(254,192,255)
writei2c 0,(" Dose1 Dose2 ",255)
end if
}
'Count the pushes of displaymode button, incrementing register 80
count 6,500, b0
if b0 > 0 then displaySwitch
'Handle battery charging
{
'HACK FIX NEEDS TO BE WORKED OUT
low 5
readadc 2, b0 'Read in the current battery level
high 5
debug b0
if b0 < 70 then 'For 5v, b0 of 90 is fully charged
high 5 'High 5v to battery
high 6 'High to charging LED indicator
else
low 5
low 6
end if
}
'Handle Servo Control
{
'servopos 7, 42
'pause 1150
'servopos 7, 222
'pause 1150
}
goto main
'Increment count register 80, or reset to 0 if last mode reached
displaySwitch:
{
peek 80, b0
b0=b0+1
writei2c 0,(254,1,255)
pause 10
if b0>2 then
b0=0
end if
poke 80, b0
debug
}
goto main
Last edited: