Does anyone have signal generation code thats output matches the propscope readings?
I am trying to write some signal generation code that the frequency per second calculated in my code will match what I'm seeing on my propscope.
Currently I'm seeing ~5.4khz on my propscope when by math from the code it should be 6khz
If someone has a known good method that produces a solid XXkhz on their prop scope, I'd appreciate being able to test it. Thanks for reading.
Currently I'm seeing ~5.4khz on my propscope when by math from the code it should be 6khz
If someone has a known good method that produces a solid XXkhz on their prop scope, I'd appreciate being able to test it. Thanks for reading.

Comments
in the Oscilloscope mode. Look on the right where it says generate. Plug in you frequency and push the generate button.
The output from the DAC card is the BNC connector closest to the Propscope box. Just connect a BNC to BNC (X1) from the DAC card output to Chan 1 Input so you can verify, as seen in the attachment.
Jim
http://obex.parallax.com/objects/47/
Jim
That is perfect except for one thing, I need to be able to generate the signal from my 40pin DIP prop chip output through a pin, and then verify the signal generation math is correct with an identical signal on the oscope.
For example, if I wanted to generate 6khz I should be able to take the clock frequency and divide it by 12000, or 6000 lows + 6000 highs like in the code below, correct?
I should see 6khz? But instead I'm seeing 5.53khz with this code as shown in the screen capture.
I have to change the divisor to about 13070 on both waitcnts to get 6khz? I'm guessing I'm doing something wrong here? Any ideas? (I've also tried it where I'm just using "cnt" instead of a variable set to cnt.)
PUB SixKhzSimulator 'DesiredRPM := 1000 toothcount := 1 previouscnt := cnt dira[c_CrankSensorOutputSimPin] := 1 repeat outa[c_CrankSensorOutputSimPin] := 1 ' output high Waitcnt((clkfreq/12000) + previouscnt) ' wait half the tooth count or 5 degrees of rotation toothcount := toothcount + 18 previouscnt := cnt outa[c_CrankSensorOutputSimPin] := 0 ' output low Waitcnt((clkfreq/12000) + previouscnt) ' wait half the tooth count or 5 degrees of rotation previouscnt := cntAlso , upgrade Propscope software to 2.00. You are pretty far behind.
http://forums.parallax.com/showthread.php?t=123627
Jim
You can find it under the help menu of the Prop Tool.
John Abshier
Look at this code and understand the math behind it. The most of what you need to do is find the number of clock ticks you need to wait before you toggle the output pin. Also, with your code, there is overhead associated with doing math inside of your waitcnt s. This will cause "clock" drift because you are not syncing up to a common point. That is, it takes time to do the math and your code does not take this extra time into account.
Take a look at this code:
{ Some of the timing code has been borrowed from Jeff Martin's Clock.spin file. You can find the full file in your Propeller Library folder. } con _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 WMin = 381 'WAITCNT-expression-overhead Minimum outFreq = 6000 'the frequency we want to generate c_CrankSensorOutoutSimPin = 1 pub generateFrequency | syncPoint, ticks dira[c_CrankSensorOutoutSimPin]~~ 'make pin an output { Some Math: First, we need to divide or time up into little pieces. This way we can figure out how many clock counts we need to wait in between toggling the pin to get our desired frequency. ticks := clock_frequency / (desired frequency * 2) the number of clock ticks to wait is the clock frequency divided by your desired frequency. In this example, we are using a 5 MHz xtal with a 16x PLL to wind the clock frequency up to 80_000_000. That is, it takes 80 million ticks to get one second. We multiply the desired frequency by two because we need to toggle the pin at twice the frequency to get a full cycle (low -> high -> back to low). Therefore, at 6 KHz * 2, (80 million ticks per second / 12_000 pin toggle per second) gives us ~6_667 ticks per pin toggle. } ticks := (clkfreq / (outFreq<<1)) #> WMin 'calculate the number of ticks to wait to generate the desired frequency syncPoint := cnt 'take a picture of the current clock count. This way, we can always sync to this point. repeat !outa[c_CrankSensorOutoutSimPin] 'toggle the pin waitcnt(SyncPoint += ticks) ' wait the appropriate number of clock counts to generate ' the proper square waveDoing this in Spin is OK, but its not so accurate. Writing assembly will get you the accuracy, but a counter module is the best way to go in my opinion.
Thank you very much.
Shamefully enough I am not familiar with how to use the counters, but I will read the suggested pages tonight and hopefully be a little familiar with using them tomorrow.
Thank you again!
The error comes from the time which the instructions need between the Waitcnt((clkfreq/12000) + previouscnt).
If you make it all relative to previouscnt, without reading the cnt register every time, the frequency should be correct:
PUB SixKhzSimulator 'DesiredRPM := 1000 toothcount := 1 previouscnt := cnt dira[c_CrankSensorOutputSimPin] := 1 repeat outa[c_CrankSensorOutputSimPin] := 1 ' output high previouscnt += clkfreq/12000 Waitcnt(previouscnt) ' wait half the tooth count or 5 degrees of rotation toothcount := toothcount + 18 outa[c_CrankSensorOutputSimPin] := 0 ' output low previouscnt += clkfreq/12000 Waitcnt(previouscnt) ' wait half the tooth count or 5 degrees of rotationAndy
@Ariba
Question about this post. I have an idea on something and would like to know if this code example is accurate enough to work with 27 Mhz frequencies?
Thanks for the good example.
Martin
Hello Martin
No, Spin is too slow for 27 MHz, even Assembly on the P1 is too slow. The only chance is to setup a counter to output a 27 MHz square wave.
Andy
Andy,
Do you feel 13 years older?
No, 14 years wiser
Happy birthday then I guess.