Does anyone have signal generation code thats output matches the propscope readings?
turbosupra
Posts: 1,088
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.)
Also , 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:
Doing 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:
Andy
@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.