Frequency Counter
Gerry Keely
Posts: 75
''Demonstration of the counter used as a frequency counter CON _clkmode = xtal1 + pll16x _XinFREQ = 5_000_000 OBJ txt : "TV_Text" PUB Go | freq txt.start(12) cognew(@entry, freq) repeat txt.out($00) 'clear the screen txt.dec(freq) 'display the value (in Hz) DAT org entry mov ctra, ctra_ 'establish mode and start counter mov frqa, #1 'increment for each edge seen mov cnt_, cnt 'setup time delay add cnt_, cntadd :loop waitcnt cnt_, cntadd 'wait for next sample mov new, phsa 'record new count mov temp, new 'make second copy sub new, old 'get delta mov old, temp 'set next delta's base wrlong new, par jmp #:loop ctra_ long %01010 << 26 + 1 'mode + APIN cntadd long 80_000_000 'wait 1 second, answer in Hz cnt_ res 1 new res 1 old res 1 temp res 1
When this program is run the TV displays value for 1 second only(ie value in cntadd).If I change cntadd to 160_000_000 it displays it for 2 seconds etc.
If I change the line "org" to "org 20" the program runs as expected.
Does anybody know why this is happening ??
Regards
Gerry
Comments
Try "cognew(@entry, @freq)".
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
“The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Thank you for you very quick response that did the trick
regards
Gerry
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
I will try this with POD today for myself and will report.
Thomas
Regards
Gerry
you are right. The Spin code or related stack will be overwritten by the assembly Cog after some minutes running. If it would be working properly the display routine should not end.
Thomas
I have debugged the assembly code with org 20 or some whatelse and it will not work properly as I was mention before.
I have also made little changes in Spin code on the loop so it will print out each second a value. And I was using the PC_Text driver for PropTerminal for my tests. With these changes the Spin code is running 28 seconds, then never a print out occur again.
I have also added some lines of code in assembly which you can uncomment for test if you have a demo board. Then you could see a blinking LED if the code is working properly. But if you use the org 20 statement after a short time several LED's will be illuminated and after 28 seconds the display loop will be run 4 times slower.
Thomas
I count 7 instructions (one being a hub operation) in the assembly loop, so it seem like it takes at least 350ns (2.86Mhz) to get back around. Although, I thought the counters were able to run on their own so that PHSA is accumulating even while this cog is busy getting through the loop.
I'm trying to count a signal that should be ~20.48Mhz. I'm happy to get an average over one second. My results with this code suggest some kind of aliasing. Am I asking too much of the prop here?
Thanks,
pgb
Thanks for your response. With a bit of fiddling, I was able to get this working. The problems were with my circuit, not the code. I've confirmed that my signal is operating at 20,480Khz.
I'm now looking for stability in that signal to better than 30bbp, which I'm not sure I can get from the prop because that depends on the stability of the prop's clock. But I'm happy to see that I'm getting something close to 20.48Mhz from my signal.
Thanks,
pgb