Timer in HCS08QG

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Timer in HCS08QG

3,100 Views
Adminsans
Contributor I

Dear Friends,

 

   I have DEM0908QG8 . i need to know how to program the timer . can anyone helpme with providing a tutorial & a sample code for timer ..

Labels (1)
0 Kudos
9 Replies

710 Views
Adminsans
Contributor I

Hello Peg

 

   Thanks for ur reply . now the sample code itself is not working when i download to the kit and run for simulation it automatically resets the simulation soon i duno why  . is the above code posted by me is correct ? I have a doubt pls do clarify 

 

With Regards,

Sans

Message Edited by Admin sans on 2009-07-30 03:16 PM
0 Kudos

710 Views
bigmac
Specialist III

Hello Sans,

 

The reset is possibly caused by the watchdog timer.  Perhaps you have code within main that loops until a counter variable reaches zero one second later.  Within this loop you will need to clear the watchdog timer.

 

If this is not the cause of your problem, you will need to post the code you are using to generate the timed delay.

 

Regards,

Mac 

0 Kudos

710 Views
Adminsans
Contributor I

Hello Mac,

 

    This is the full code 

 

 


#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */


 void main(){
 
PTBDD |= (unsigned char)0x40;/* Set PTB6 as output   */
MTIMCLK = 0x08; /* Bus clock 256 divider */
MTIMMOD = 0x77; /* Count to 0xFF */
MTIMSC  = 0x60; /* Enable overflow interrupt and start counter */
 }
__interrupt void Vmtim_isr(void)

{
     PTBD_PTBD6 = ~PTBD_PTBD6;  /* Toggle the PTB pin */
     MTIMSC;             /* Clear the TOF flag */
     MTIMSC_TOF = 0;
}

 

 


when this code is compiled and simulated the same way as i said before during simulation it resets automatically within a second .. Could u pls help me in giving the prog for a timer using timer flag based on the time the led should blink c...

 

 

 

With Regards,

Sans

 

0 Kudos

710 Views
peg
Senior Contributor IV

Hello,

 

If you read section 5.4 of the datasheet you will see that the QG's watchdog is enabled by default. This means that you either have to disable this function or periodically reset the watchdog timer to prevent it from timing out and resetting the device.

 

0 Kudos

710 Views
Adminsans
Contributor I

Hello Peg,

 

   How to disable that function of watchdog ? could u pls help me out

 

With Regards,

Sans

0 Kudos

710 Views
peg
Senior Contributor IV

Hello,

 

To disable the COP you need to clear the COPE bit (7) of the SOPT1 register. This register is "write once" so you need to ensure that this register is only written once in all of your code. Also, because of this,  once you disable it you can't re-enable it later in your code.

0 Kudos

710 Views
Adminsans
Contributor I

Hello Peg,

 

    This is the sample code given at preipheral module quick reference.pdf for Timer . The following code generates a time delay of 7.68 ms also it uses timer interrrupt mode for togling LED . I need a code which generates a time delay of 1s and by monitoring the TOF flag i have to toggle LED could you please help me ... 

 

 


Code :

 

 

      PTBDD |= (unsigned char)0x40; /* Set PTB6 as output        */
 MTIMCLK = 0x08;                  /* Bus clock 256 divider */
 MTIMMOD = 0x77;                  /* Count to 0xFF */
 MTIMSC = 0x60;                   /* Enable overflow interrupt and start counter */

 

 

__interrupt void Vmtim_isr(void)
{
     PTBD_PTBD6 = ~PTBD_PTBD6;      /* Toggle the PTB pin */
     MTIMSC;                /* Clear the TOF flag */
     MTIMSC_TOF = 0;
}
 

 


With Regards,

 

Sans

 

 

 

0 Kudos

710 Views
peg
Senior Contributor IV

Hello sans,

 

The MTIM does not directly support delays this long. One way around this would be to set the timer modulo to approxiamately 0x9B (I don't know your exact BUSCLK). This will give a delay of 10ms. Now you just count off one hundred of these and you have 1s.

To disable the interrupts change your MTIMSC setup to 0x20.

Now you just put an if statement in your main loop testing TOF in MTIMSC, count of 100 TOF's resetting TOF as you go. When you do the tenth one you also toggle the output.

 

0 Kudos

710 Views
peg
Senior Contributor IV

Hello and welcome to the fora, Admin sans,

 

Putting "QG timer" into the search box should yield some useful information.

 

0 Kudos