Why can't I get a higher frequency square wave?
W9GFO
Posts: 4,010
I am in the process of going through the PE Kit labs again. This code is essentially the same as in the lab only I have increased (decreased) the values to see where the prop couldn't keep up.
16 khz is the highest freq where I could get a wave with equal high and low time - more or less. That makes 5,000 clock cycles to go through the repeat loop.
Here I have a square wave at 16 khz. the scope shows it high for 30 uS and low for 32 uS.
So, I am wondering;
Why can't I get a higher freq to work?
Why is it low longer than high?
And yes, I know there are better ways to make a square wave - says so right in the lab...
Rich H
Edited to add comments to code, it makes sense now.
Post Edited (W9GFO) : 4/27/2009 6:39:08 AM GMT
16 khz is the highest freq where I could get a wave with equal high and low time - more or less. That makes 5,000 clock cycles to go through the repeat loop.
Here I have a square wave at 16 khz. the scope shows it high for 30 uS and low for 32 uS.
So, I am wondering;
Why can't I get a higher freq to work?
Why is it low longer than high?
And yes, I know there are better ways to make a square wave - says so right in the lab...
Rich H
CON _xinfreq = 5_000_000 _clkmode = xtal1 + pll16x VAR long swStack[noparse][[/noparse]40] byte swCog PUB Launch swCog := cognew(SquareWave(24,clkfreq/32000, clkfreq/16000), @swStack ) PUB SquareWave( pin, tHigh, tCycle )| tC, tH dira[noparse][[/noparse]pin]~~ outa[noparse][[/noparse]pin]~ tC := cnt repeat ' (pin still low) outa[noparse][[/noparse]pin]~~ ' make pin high tH := tC + tHigh ' (re)capture a time in the future where the pin will go low tC += tCycle ' (re)capture a time in the future where the pin will go high waitcnt(th) ' sit tight until time to go low outa[noparse][[/noparse]pin]~ ' make pin low waitcnt(tC) ' wait again until time to go high ' end - go back and do it again
Edited to add comments to code, it makes sense now.
Post Edited (W9GFO) : 4/27/2009 6:39:08 AM GMT
Comments
-Phil
...I get it now, it took commenting each line for the answer to reveal itself. Original post edited to include comments.
Rich H
Post Edited (W9GFO) : 4/27/2009 6:44:17 AM GMT
If you want symmetrical signal, your only chance is to reduce number of instructions in the loop by using xor operator. My first guess is that accessing the outa without [noparse][[/noparse] ] is faster than giving a bit number.
If you have to create plain squarewaves this could also be done with one of the counters each COG has. This still can be done in SPIN if you are afraid of using PASM.
Or you can switch to PASM of course.
3,600 1,800 clock cycles to toggle a pin!
Post Edited (W9GFO) : 4/27/2009 4:57:52 PM GMT
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle
Doing high speed stuff in assembly is the best way to do it. There are some good 3rd party tools (not free) like ImageCraft's C compiler and JDForth (www.jacobsdesign.com.au/software/jdforth/jdforth.php).