Hello,
I am fairly new to picaxe: this is my first project, which has been going well until I started using pwmout to control a motor.
It is a program to test a thermostatic control system, which needs to adjust a temperature by means of a pwm controlled dc motor.
I have had a series of headaches involving not being able to start, stop, or restart the motor after stopping.
Unfortunately the code almost completely fills the 40X1 chip that i am using, hence posting it is tricky. So I have cut and pasted a few bits of it into a smaller version, which now works perfectly. However I am struggling to see what in my larger version can prevent it from working.
Question: could someone please have a look at the code below, and tell me if there are any known issues that might prevent this from working if certain other commands are used in between the motor start/stop commands?
The rest of my program uses an interrupt triggered by timer overflow to measure temperatures (with pulsin) and pressures (with readadc10). It also uses the i2c bus to read from the ds1307 clock and drive an LCD.
Note that the code following works, I am just inquiring if there are known issues with doing this sort of stuff, which makes my other code fail...
...Someone is going to tell me to comment out the rest of the program piece by piece until it works. I will try to do this now, but I also tried this with a previous version of the code and it yielded nothing sensible. I fear there is something weirder than usual going on here, so hence the cry for help!
Thanks in anticipation...
Picaxe 40X1
Prog Editor 5.2.0
I am fairly new to picaxe: this is my first project, which has been going well until I started using pwmout to control a motor.
It is a program to test a thermostatic control system, which needs to adjust a temperature by means of a pwm controlled dc motor.
I have had a series of headaches involving not being able to start, stop, or restart the motor after stopping.
Unfortunately the code almost completely fills the 40X1 chip that i am using, hence posting it is tricky. So I have cut and pasted a few bits of it into a smaller version, which now works perfectly. However I am struggling to see what in my larger version can prevent it from working.
Question: could someone please have a look at the code below, and tell me if there are any known issues that might prevent this from working if certain other commands are used in between the motor start/stop commands?
The rest of my program uses an interrupt triggered by timer overflow to measure temperatures (with pulsin) and pressures (with readadc10). It also uses the i2c bus to read from the ds1307 clock and drive an LCD.
Note that the code following works, I am just inquiring if there are known issues with doing this sort of stuff, which makes my other code fail...
Code:
symbol mwt=b9 'mwt in tenths of degrees C above 30°
symbol settmp= 110 'equivalent to 41 degC
setfreq m8 'set the clock speed to 8MHz
mwt = 0
main:
gosub setpwm
sertxd ("motor started",13,10)
for b0 = 0 to 20 ;delay
pause 250
next b0
pwmout 1,253,0 ;stop the motor
pwmout 1 off
sertxd ("motor stopped",13,10)
for b0 = 0 to 20 ;delay
pause 250
next b0
gosub setpwm
sertxd ("motor started",13,10)
for b0 = 0 to 20 ;delay
pause 250
next b0
pwmout 1,253,0 ;stop the motor
pwmout 1 off
sertxd ("motor stopped",13,10)
let mwt=mwt+83
goto main
'****************************************
setpwm:
high portc 1 ;make sure this is configured as an output
low portc 1
if mwt<settmp then
goto warmup
endif
;cooldown:
low portc 7
let b3 = mwt-settmp
goto adjusttemp
warmup:
high portc 7 ;energise the pin to reverse the motor
let b3 = settmp-mwt
adjusttemp:
for b2 = 8 to 1 step -1
let w2 = b2*127
sertxd ("w2=",#w2,13,10)
if b3>91 then exit
let b3 = b3+13
next b2
pwmout 1,253,w2 '91 = 13*(8-1)
return ;return from setpwm...
Thanks in anticipation...
Picaxe 40X1
Prog Editor 5.2.0