Shop OBEX P1 Docs P2 Docs Learn Events
simple PWM code — Parallax Forums

simple PWM code

propeller-kidpropeller-kid Posts: 2
edited 2011-10-12 14:57 in Propeller 1
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
[/SIZE][/FONT]
[FONT=Arial][SIZE=2][SIZE=2][FONT=Arial]_CLKMODE=XTAL1+ PLL2X 'The system clock spec[/FONT][/SIZE]
[SIZE=2][FONT=Arial]_XINFREQ = 5_000_000 'crystal frequency [/FONT][/SIZE]
[SIZE=2][FONT=Arial]VAR[/FONT][/SIZE]
[SIZE=2][FONT=Arial]long pulsewidth[/FONT][/SIZE]
[SIZE=2][FONT=Arial]long cycle_time[/FONT][/SIZE]
[SIZE=2][FONT=Arial]long period[/FONT][/SIZE]
[SIZE=2][FONT=Arial]PUB Go[/FONT][/SIZE]
[SIZE=2][FONT=Arial]dira[7]~~ 'set output line[/FONT][/SIZE]
[SIZE=2][FONT=Arial]ctra[30..26]:=%00100 'run PWM mode[/FONT][/SIZE]
[SIZE=2][FONT=Arial]ctra[5..0]:=7 'Set the "A pin" of this cog[/FONT][/SIZE]
[SIZE=2][FONT=Arial]frqa:=1 'Set this counter's frqa value to 1[/FONT][/SIZE]
[SIZE=2][FONT=Arial]PulseWidth:=-5000 'Start with position=5_000[/FONT][/SIZE]
[SIZE=2][FONT=Arial]Cycle_time:=clkfreq/1000 'Set the time for the pulse width to 1 ms[/FONT][/SIZE]
[SIZE=2][FONT=Arial]period:=cnt 'Store the current value of the counter[/FONT][/SIZE]
[SIZE=2][FONT=Arial]repeat 'PWM routine.[/FONT][/SIZE]
[SIZE=2][FONT=Arial]phsa:=PulseWidth 'Send a high pulse for PulseWidth counts[/FONT][/SIZE]
[SIZE=2][FONT=Arial]period:=period + Cycle_time 'Calculate cycle time[/FONT][/SIZE]
[SIZE=2][FONT=Arial]waitcnt(period) 'Wait for the cycle time[/FONT][/SIZE]
Any help.


Thanks in advance
Propeller kid


Comments

  • propeller-kidpropeller-kid Posts: 2
    edited 2011-10-12 14:07
    Aha Got it.
    After repeat it should be an indentation with a tab..hehhehe
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-10-12 14:57
    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.
Sign In or Register to comment.