Software Real-Time Clock on HC12

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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


Re: Software Real-Time Clock on HC12
Quoted text here. Click to load it

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

Steve
http://www.fivetrees.com



Re: Software Real-Time Clock on HC12
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...


Re: Software Real-Time Clock on HC12

Quoted text here. Click to load it

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

Quoted text here. Click to load it

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

Quoted text here. Click to load it

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

Quoted text here. Click to load it

Good plan ;).

Steve
http://www.fivetrees.com



Re: Software Real-Time Clock on HC12
Quoted text here. Click to load it

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.

Re: Software Real-Time Clock on HC12
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


Site Timeline