SX48 counter
David Eames
Posts: 4
I am new to programming and the SX48. I want to input a square wave that will run from around 12 to 140hz and keep a running tally of the number of pulses that can be fetched by an Xbee device. This sounds like it should be pretty simple but I have been struggling. Any help or samples would be greatly appreciated.
Dave E.
Dave E.
Comments
If you are thinking of using the hardware counters, it's not going to be that easy. There isn't an easy way to actually read what the count is.
If you are using SX/B there is a COUNT command that should do the job.
Can you post what you have tried ?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1st rule of finance...Don't lose money.
Never be ashamed of making an honest·profit.
Live within your means...Make do, or do without.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Unlike the SX48 16-bit counter, the 8-bit RTCC counter IS easily read.
Just set RTCC to zero, pause for 1 second and read RTCC.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1st rule of finance...Don't lose money.
Never be ashamed of making an honest·profit.
Live within your means...Make do, or do without.
·
If the commitment is made to pin generated interrupt *hardware* then it can be a one-way street. For example, in my code above, I presume that the sample time is constant -- i.e. it's counting samples received in fairly precise 10ms frames (although there's no flag for the mainline). So if sample windows were an issue, a pure RTCC interrupt would prevent that (of course, you could back-calculate a revised RTCC and check if the pin or overflow caused the interrupt, but at that point, my own taste is to just get the ISR wound up tight enough to capture and parse relevant pin states at regular intervals).
Another way to put it -- with a few changes to bit frame counts, Jon's ISR based serial TX/RX w/buffers could be dropped right in w/o changes to firmware nor hardware.
David -- here's a slightly revised version that sets a flag to let the mainline know that the count has been "captured". The scenario below presumes that the mainline will never take more than 10ms before getting around to checking/clearing the flag (to keep this example relatively simple):
But it's a matter of style and need and preference, of course. If the SX is standalone and needs no timing-dependent routines, the RTCC is always elegant. The real question is what are you doing w/the counts once you have them? Sending them to another device? Displaying on an LCD? Writing to EEPROM?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Post Edited (Zoot) : 12/7/2009 2:42:43 AM GMT
Or go back to Bean what suggested -- doing a COUNT in the mainline (if you can afford to take time off from counting pulses to do your serial comms and other work).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php