Reply by Daniel White July 1, 20042004-07-01
I found the answer to my problem after more experimentation. The key is to
use the FLMC to force the initial delay into the modulus counter and then
just let it use the 5mS delay when the first one times out. What seems to
have been happening was that the 20mS never got loaded even though I was
writing it before MODMC was enabled.

So, here is the version that works for anyone who wants to change the
modulus counter on the fly. This creates a 20mS delay before the first
iteration of the ISR and then a 5mS delay every time after that:
4178 ; //Set up modulus for executive
4178 ; MCCNT = EXECUTIVE_POWERUP_DELAY;
4178 CC7530 ldd #30000
417B 7C0076 std 0x76
417E .dbline 339
417E ;
417E ; //Enable the modulus counter, enable int, mod mode, force load and
enable counter at bus/16
417E ; MCCTL = 0b11001111;
417E C6CF ldab #207
4180 7B0066 stab 0x66
4183 .dbline 342
4183 ;
4183 ; /* set the modulus timer for next time and every time thereafter */
4183 ; MCCNT = EXECUTIVE_TIME_IN_CLOCK_TICKS;
4183 CC1D4C ldd #7500
4186 7C0076 std 0x76 And the interrupt service routine doesn't need to do anything except clear
the flag...

4084 ; #pragma interrupt_handler RealTimeOS_ISR
4084 ; void RealTimeOS_ISR()
4084 ; {
4084 .dbline 73
4084 ; /* clear the interrupt flag */
4084 ; MCFLG |= BIT(7);
4084 1C006780 bset 0x67,#128
4088 .dbline 74
4088 ; Executive();
4088 164056 jsr _Executive
408B .dbline -2
408B .dbline 76
408B ;
408B ; }
408B L12:
408B .dbline 0 ; func end
408B 0B rti -----Original Message-----
From: Daniel White [mailto:]
Sent: Thursday, July 01, 2004 10:10 AM
To:
Subject: [68HC12] Need help with modulus down counter Anyone out there that has experience with the modulus down counter on the
S12?

Section 3.3.29 of the S12 ECT block user guide (S12ECT16B8V1.pdf)
describes
the MCCNT register as having a load register. This description says that,
if
the counter is enabled (MODMC=1), writing to the MCCNT register won't
update
the counter until it has finished counting down to 0. I am trying to use
this feature to my advantage but this doesn't seem to be how it really
works.

What I want to do is delay 20mS before the first execution of my RTOS and
then run it every 5mS after that. I thought this is what I would get if I
set MCCNT to 20mS and then enable the counter and then set MCCNT to 5mS.

So this is what I tried (bus clock 24MHz):
410B ; //Set up modulus for executive
410B ; MCCNT = EXECUTIVE_POWERUP_DELAY;
410B CCEA60 ldd #0xea60
410E 7C0076 std 0x76
4111 .dbline 296
4111 ;
4111 ; //Enable the modulus counter, enable int, mod mode and
enable counter at bus/8
4111 ; MCCTL = 0b11000110;
4111 C6C6 ldab #198
4113 7B0066 stab 0x66
4116 .dbline 299
4116 ;
4116 ; /* set the modulus timer for next time and every time
thereafter */
4116 ; MCCNT = EXECUTIVE_TIME_IN_CLOCK_TICKS;
4116 CC3A98 ldd #15000
4119 7C0076 std 0x76

But on my scope I see that the first interrupt occurs about 3.5mS after
powerup (only about 2.8mS after the initialization code) and then every
one
after that is 5mS apart as desired. The only way I can get the desired
behavior is to initialize the counter for 20mS and then re-initialize it
to
5mS inside the interrupt which I didn't think I should have to do. I'm
concerned that if I reset it every time inside my ISR that it will lose
the
interrupt latency time and I will have a cumulative error. This means that
I
would have to put a check in to only initialize it on the first iteration
of
the ISR.

I think I'm just missing the elegant solution.

Any help would be appreciated.

Daniel White

Ph (812) 376-0985
Gale Banks Engineering
2228 Lafayette Ave.
Columbus, IN 47201

Visit us on the web: www.bankspower.com
----
--
Yahoo! Groups Links

a.. To


Reply by Daniel White July 1, 20042004-07-01
Anyone out there that has experience with the modulus down counter on the
S12?

Section 3.3.29 of the S12 ECT block user guide (S12ECT16B8V1.pdf) describes
the MCCNT register as having a load register. This description says that, if
the counter is enabled (MODMC=1), writing to the MCCNT register won't update
the counter until it has finished counting down to 0. I am trying to use
this feature to my advantage but this doesn't seem to be how it really
works.

What I want to do is delay 20mS before the first execution of my RTOS and
then run it every 5mS after that. I thought this is what I would get if I
set MCCNT to 20mS and then enable the counter and then set MCCNT to 5mS.

So this is what I tried (bus clock 24MHz):
410B ; //Set up modulus for executive
410B ; MCCNT = EXECUTIVE_POWERUP_DELAY;
410B CCEA60 ldd #0xea60
410E 7C0076 std 0x76
4111 .dbline 296
4111 ;
4111 ; //Enable the modulus counter, enable int, mod mode and
enable counter at bus/8
4111 ; MCCTL = 0b11000110;
4111 C6C6 ldab #198
4113 7B0066 stab 0x66
4116 .dbline 299
4116 ;
4116 ; /* set the modulus timer for next time and every time
thereafter */
4116 ; MCCNT = EXECUTIVE_TIME_IN_CLOCK_TICKS;
4116 CC3A98 ldd #15000
4119 7C0076 std 0x76

But on my scope I see that the first interrupt occurs about 3.5mS after
powerup (only about 2.8mS after the initialization code) and then every one
after that is 5mS apart as desired. The only way I can get the desired
behavior is to initialize the counter for 20mS and then re-initialize it to
5mS inside the interrupt which I didn't think I should have to do. I'm
concerned that if I reset it every time inside my ISR that it will lose the
interrupt latency time and I will have a cumulative error. This means that I
would have to put a check in to only initialize it on the first iteration of
the ISR.

I think I'm just missing the elegant solution.

Any help would be appreciated.

Daniel White

Ph (812) 376-0985
Gale Banks Engineering
2228 Lafayette Ave.
Columbus, IN 47201

Visit us on the web: www.bankspower.com