4 PWM problem
Hello, I am new to propeller, please help, I am out of ideas what is wrong. I have used PWMasm module from object exchange.
So I would like to drive 4 motors using allegro A3649 chips. So far so good. Motors are running, but I can't get running all 4 pwm cogs. I get only any 2 of them.
So I would like to drive 4 motors using allegro A3649 chips. So far so good. Motors are running, but I can't get running all 4 pwm cogs. I get only any 2 of them.
CON _clkmode = xtal1 + pll16x
_xinfreq = 5_000_000 '!
led = 27
pwm1pin = 18 ' engine 1
pwm2pin = 16 ' engine 2
pwm3pin = 14 ' engine 3
pwm4pin = 11 ' engine 4
pog = 1
OBJ
pwm1 : "pwmasm"
pwm2 : "pwmasm"
pwm3 : "pwmasm"
pwm4 : "pwmasm"
PUB init
waitpeq(|< pog, |< pog, 0) 'Wait for pog to go high
dira[noparse][[/noparse]led]~~
outa[noparse][[/noparse]led]~~ ' LED on
waitcnt(clkfreq * 5 + cnt) ' PAUSE 5 s
outa[noparse][[/noparse]led]~ 'LED off
main
PUB MAIN
pwm1.start(pwm1pin)
pwm2.start(pwm2pin)
pwm3.start(pwm3pin)
pwm4.start(pwm4pin)
pwm1.SetPeriod(80000)
pwm2.SetPeriod(80000)
pwm3.SetPeriod(80000)
pwm4.SetPeriod(80000)
pwm1.SetDuty(20)
pwm2.SetDuty(20)
pwm3.SetDuty(20)
pwm4.SetDuty(20)
{A simple pwm object based on code from AN001 - propeller counters
Author: Jev Kuznetsov
date : 16 Oktober 2007
usage
OBJ
pwm : pwmAsm
....
pwm.start( Pin) ' start pwm
pwm.SetPeriod( period ) ' set pwm period in clock cycles
pwm.SetDuty( duty) ' set duty in %
pwm.Stop
}
CON _clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
VAR
long cogon, cog
long sDuty ' order important (the variables are read from memory in this order)
long sPinOut
long sCtraVal
long sPeriod
PUB Start( Pin) : okay
'start pwm on Pin @ 80 kHz
longfill(@sDuty, 0, 4)
sDuty := 50 ' default duty
sPinOut := |< Pin
sCtraVal := %00100 << 26 + Pin
sPeriod := 1000
cognew(@entry,@sDuty)
PUB stop
'' Stop object - frees a cog
if cogon~
cogstop(cog)
longfill(@sDuty, 0, 4)
PUB SetPeriod(counts)
' set pwm period in clock cycles, frequency = (_clkfreq / period)
sPeriod := counts
PUB SetDuty(counts)
if (counts < 0)
counts := 0
if (counts > 100)
counts := 100
sDuty :=counts*sPeriod/100
DAT
'assembly cog which updates the PWM cycle on APIN
'for audio PWM, fundamental freq which must be out of auditory range (period < 50µS)
org
entry mov t1,par 'get first parameter
rdlong value, t1
add t1,#4
rdlong pinOut, t1
or dira, pinOut ' set pinOut to output
add t1, #4
rdlong ctraval, t1
mov ctra, ctraval 'establish counter A mode and APIN
add t1, #4
rdlong period, t1
mov frqa, #1 'set counter to increment 1 each cycle
mov time, cnt 'record current time
add time, period 'establish next period
:loop rdlong value, par 'get an up to date pulse width
waitcnt time, period 'wait until next period
neg phsa, value 'back up phsa so that it trips "value" cycles from now
jmp #:loop 'loop for next cycle
period res 1
time res 1
value res 1
t1 res 1
pinOut res 1
ctraval res 1

Comments
Commented out the wait for pong to go high line since I have no switch on the Demoboard.
Changed the pin constants to pins with LEDs on the Demoboard
Running the program all 4 of the pwm pins light up which leads me to believe that all 4 pwm cogs have started. Is the posted program your complete program? If your program is longer could it be starting other cogs?
John Abshier
But the problem is still there.
I mesured actual outputs and get the following:
pwm1.start(pwm1pin) ' here is "1" pwm2.start(pwm2pin) ' here is "1" pwm3.start(pwm3pin) ' here is nice 1000Hz 20% duty PWM pwm4.start(pwm4pin) ' here is nice 1000Hz 20% duty PWM pwm1.SetPeriod(80000) pwm2.SetPeriod(80000) pwm3.SetPeriod(80000) pwm4.SetPeriod(80000) pwm1.SetDuty(20) pwm2.SetDuty(20) pwm3.SetDuty(20) pwm4.SetDuty(20)If I comment out or change order I could get PWM on any 2 pins but not on all 4 simultaneous.
For a moment yes, but it is only for a test purposes of my new 4 wheel mini sumo robot.
this cannot be a full program.
where is the OBJ-section
where is the CON-section ?
if your program has only a few lines more please post the COMPLETE program here
best regards
Stefan