There are 6 messages in this thread.
You are currently looking at messages 0 to 6.
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
"Christian Winter" <c...@gmail.com> wrote in message news:1...@p10g2000cwp.googlegroups.com... > 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. 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
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
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...
"Christian Winter" <c...@gmail.com> wrote in message news:1...@e56g2000cwe.googlegroups.com... > With "heartbeat" do you mean using the real-time interrupts? I mean use one of the timers to generate a regular interrupt. > If so, it > would be best if I could set it up such that it is called every second > to increment the clock. If your only realtime requirement is updating the clock, then sure. But one often needs to have finer time control than 1s. > I also found someone suggesting to use the pulse-width modulator, but I > am unsure as to how to do that. Errrr.... PWM is not directly appropriate. However the timer may well be a potential interrupt source. > Getting out the HC12 data sheet again... Good plan ;). Steve http://www.fivetrees.com
"Steve at fivetrees" <s...@NOSPAMTAfivetrees.com> writes: > "Christian Winter" <c...@gmail.com> wrote > > > With "heartbeat" do you mean using the real-time interrupts? > > I mean use one of the timers to generate a regular interrupt. > > > If so, it > > would be best if I could set it up such that it is called every second > > to increment the clock. > > If your only realtime requirement is updating the clock, then sure. But one > often needs to have finer time control than 1s. > > > I also found someone suggesting to use the pulse-width modulator, but I > > am unsure as to how to do that. > > Errrr.... PWM is not directly appropriate. However the timer may well be a > potential interrupt source. > > > Getting out the HC12 data sheet again... > > Good plan ;). 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.