Software Real-Time Clock on HC12

Hi!

I am trying to implement a software real-time clock on the HC12 using the timer module. I am pretty much unable to do it at this point and was hoping that someone could point me in the right direction -- perhaps even coded examples that could serve as a way to better understand it. I need to keep track of a 24 hour day, no need for any actual dates. I can code using either assembler or C++. The clock should run independently so other code can be inserted without effort.

Thanks for all and any help!

Christian

Reply to
Christian Winter
Loading thread data ...

I suggest you setup a heartbeat interrupt - say 5ms or 1ms, depending on the granularity you need - and do the time maintenance therein.

Steve

formatting link

Reply to
Steve at fivetrees

if (RTC_tick>= XX ){ seconds++; RTC_tick = 0;

if (seconds>=60){ minutes++; seconds = 0; } if (minutes>=60){ hours++; minutes = 0; } if (hours>=24){ days++; hours = 0; } }

You have to define XX based on the heatbeat time you setup. Eric

Reply to
Eric

With "heartbeat" do you mean using the real-time interrupts? If so, it would be best if I could set it up such that it is called every second to increment the clock.

I also found someone suggesting to use the pulse-width modulator, but I am unsure as to how to do that.

Getting out the HC12 data sheet again...

Reply to
Christian Winter

I mean use one of the timers to generate a regular interrupt.

If your only realtime requirement is updating the clock, then sure. But one often needs to have finer time control than 1s.

Errrr.... PWM is not directly appropriate. However the timer may well be a potential interrupt source.

Good plan ;).

Steve

formatting link

Reply to
Steve at fivetrees

Looking at the data manual finds the Clock Generation Module, Realtime Interrupt. Interrupts occur at one of eight program-selectable rates in binary fractions of oscillator frequency. Use a power-of-two oscillator and you can get exact time-of-day; otherwise, throw in a fudge factor from time to time.

Reply to
Everett M. Greene

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.