propeller-kid
10-12-2011, 08:55 PM
Hello there,
I am a propeller beginner and trying to write a simple PWM code without any object files.
Here is a code snippet by Harprit Sandhu from his book.But it is not working on my proppler Robot control board.Its the propeller P8X32A-Q44 chip. My propeller version is1.3 .The code was written for 1.2.6.Does it even matter.I simply copied the code and pasted on my propeller file and checked the output at pin 7 but its not working.
CON
_CLKMODE=XTAL1+ PLL2X 'The system clock spec
_XINFREQ = 5_000_000 'crystal frequency
VAR
long pulsewidth
long cycle_time
long period
PUB Go
dira[7]~~ 'set output line
ctra[30..26]:=%00100 'run PWM mode
ctra[5..0]:=7 'Set the "A pin" of this cog
frqa:=1 'Set this counter's frqa value to 1
PulseWidth:=-5000 'Start with position=5_000
Cycle_time:=clkfreq/1000 'Set the time for the pulse width to 1 ms
period:=cnt 'Store the current value of the counter
repeat 'PWM routine.
phsa:=PulseWidth 'Send a high pulse for PulseWidth counts
period:=period + Cycle_time 'Calculate cycle time
waitcnt(period) 'Wait for the cycle timeAny help.
Thanks in advance
Propeller kid
I am a propeller beginner and trying to write a simple PWM code without any object files.
Here is a code snippet by Harprit Sandhu from his book.But it is not working on my proppler Robot control board.Its the propeller P8X32A-Q44 chip. My propeller version is1.3 .The code was written for 1.2.6.Does it even matter.I simply copied the code and pasted on my propeller file and checked the output at pin 7 but its not working.
CON
_CLKMODE=XTAL1+ PLL2X 'The system clock spec
_XINFREQ = 5_000_000 'crystal frequency
VAR
long pulsewidth
long cycle_time
long period
PUB Go
dira[7]~~ 'set output line
ctra[30..26]:=%00100 'run PWM mode
ctra[5..0]:=7 'Set the "A pin" of this cog
frqa:=1 'Set this counter's frqa value to 1
PulseWidth:=-5000 'Start with position=5_000
Cycle_time:=clkfreq/1000 'Set the time for the pulse width to 1 ms
period:=cnt 'Store the current value of the counter
repeat 'PWM routine.
phsa:=PulseWidth 'Send a high pulse for PulseWidth counts
period:=period + Cycle_time 'Calculate cycle time
waitcnt(period) 'Wait for the cycle timeAny help.
Thanks in advance
Propeller kid