Shop OBEX P1 Docs P2 Docs Learn Events
Need help for this code — Parallax Forums

Need help for this code

anita1984anita1984 Posts: 23
edited 2008-11-03 20:09 in Propeller 1
Hello , i wrote this code to generate a frequency from 1Hz to 4KHz with duty cycle 50% , but the output on pin 1 isn't not for my need , no frequency :
CON
_clkmode = xtal1 + pll16x ' clk speed = external * 16 for 80 mhz
_xinfreq = 5_000_000 '5mhz external crystal

Pinout = 1

Var
long FreqOn, FreqOff

Pub Run|i
repeat
repeat i from 1 to 4000
FreqDuty(i,50) ' this will generate a loop from 1hz to 4,000hz then start over.

Pub FreqDuty(Frequency, Duty)
waitcnt((( clkfreq/frequency)*(100-Duty))/100 +cnt) ' wait for off part of duty cycle
outa[noparse][[/noparse]pinout]~~ 'Pin High
waitcnt((((clkfreq/frequency)*duty)/100) + cnt) ' Now the pin is high wait for the on part.
outa[noparse][[/noparse]pinout]~ ' Make the pin LOW

Comments

  • hippyhippy Posts: 1,981
    edited 2008-11-03 20:09
    You need to make the pin an output ... DIRA[noparse][[/noparse]pinout] := 1, or DIRA[noparse][[/noparse]pinout]~~
Sign In or Register to comment.