PDA

View Full Version : What is the simplest way to get a second tick



websmith
- 28th April 2011, 09:31
Hi, I'm making an ampere-hour meter to monitor battery consumption on an electric boat motor. I have the shuntderived mV measurement and A/D part sorted, now I just need to integrate amps with time. I have it working in a simple loop with a constant using 'pause' set to about 490mS, and it ticks over roughly every second and takes a reading. Is there a better way using a built in timer or perhaps an external 1 sec tick derived from a 32.768 xtal driving an interrupt, if you could point me to an example perhaps?

cncmachineguy
- 28th April 2011, 12:13
Well it depends on what you mean by better. If it is working for you now with no issues, I would say you are done. If you want to start using the uP for more stuff, and timing is an issue, use an interrupt or DT_INT elasped timer to drive the ticks.

Or for a somewhat middle of the road approach, you could set up a timer to free run, then poll that timers flag (ie: PIRx.x) in your main. when its set, gosub to update a counter. From there, if the count=time to take reading, take the reading and reset the counter. You can set this up with little trouble and it will be as accurate as the time between polling the flag. depending on your uP, using pre/post scalers and PR if available, it is not too hard to do.

IMHO, adding external things does not make this easier at all.

Ramius
- 28th April 2011, 12:26
This may be more than you are after and STMicroelectronics makes a series of RTC (Real Time Clock) chips such as the M41T62,63,64,65 and others that might be worth looking at as a way of know the exactly time if that is important?

Best, Ed

sayzer
- 28th April 2011, 12:50
DS1307 has that feature.

It gives you a tick at the interval you set.
And it is a RTC.

___________

fratello
- 28th April 2011, 19:47
And here : http://www.josepino.com/microcontroller/timebase_generator it's something interesting..."Update: The reason why this projects is not longer available is because you can buy a $1 USD clock and use the circuit as timebase"

cncmachineguy
- 28th April 2011, 20:05
With all these valid replies for external components, I feel I should clarify my statement


IMHO, adding external things does not make this easier at all.


I do not meant to say adding any of the above is hard. Just that for this app, with what little explanation there is, twiddling bits seems the easiest approach.
And for me, anytime I can leave a few parts off the board, life got a little bit easier. :)

Bruce
- 28th April 2011, 21:09
See this thread http://www.picbasic.co.uk/forum/showthread.php?t=2129

rmteo
- 7th May 2011, 15:12
You can have multiple ticks (of different durations) without additional parts using the technique in post #10 here http://www.picbasic.co.uk/forum/showthread.php?t=14738&p=102213#post102213

websmith
- 9th May 2011, 11:08
Hi Guys
Thanks for the answers, I had forgotten how easy it was to use Bruce's instant interrupts, and that is how I did it, all I needed was a 1 second tick to start the a/d sample and the A/H integration. All sorted now.

Bruce
- 10th May 2011, 15:46
I had forgotten how easy it was to use Bruce's instant interrupts
Credit for instant interrupts belongs to Darrel Taylor..;o)