PDA

View Full Version : simple PWM code



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

propeller-kid
10-12-2011, 09:07 PM
Aha Got it.
After repeat it should be an indentation with a tab..hehhehe

Cluso99
10-12-2011, 09:57 PM
propeller-kid: Welcome to this fabulous forum and the prop world :)

Glad you resolved your problem. At any time you have a problem, just ask. There are many on these forums just itching to answer problems and provide great advice.

PropTool has hardly changed since the original release. Just a couple of very minor bug fixes. Most are in the documentation that accompanies proptool, so make sure you take a look at the files that come with it.