yecosuma - 68hc08gp32  / 68hc08gt32

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

yecosuma - 68hc08gp32  / 68hc08gt32

1,470 Views
yecosuma
Contributor III
hello  I like of microcontroller freescale, i am a novice but i want expert.   please help me
i want to do a program whit a input capture, whit 68hc08gp32 for measure of width of pulse and frecuency, I program in ansi -C , I dont know how i do the program, I understand the procedure but , i dont can whit this,, please anybody  send me a example, I am realy learn only tanks at the expert that help me.    my mail is yecosuma@yahoo.es please help me i want learn more !!!!!!!!!!! 
 
 
 
 
 
Added p/n to subject.


Message Edited by NLFSJ on 2009-02-05 11:19 AM
Labels (1)
0 Kudos
3 Replies

255 Views
Nouchi
Senior Contributor II
Hello,

The following example was build on a MC9S08GT32, it would be similar for a HC908GP32, an this function measure line frequency and return 50 or 60 hz or 0 if a failure.
This example is made with a polling scheme, it could be implemented with interrupts for a continuous measurement.

You probably want  something like this:
Code:
#define HZ_50_L 44827       /* low value 50 hz */#define HZ_50_H 49545       /* hight value 50 hz */#define HZ_60_L 36962       /* low value pour 60 hz */#define HZ_60_H 41681       /* hight value 60 hz *//* measure AC line period *//* return 50 if 50Hz, 60 if 60Hz, 0 if failure */byte get_line_freq(void){word value1;word value2;byte cpt_tof = 0;  TPM2SC = 0x0A;                        // bus rate clock, prescale = 4  TPM2MOD = 0;                          // free-running counter    TPM2C1SC = 0x0C;                      // input capture on both edges  TPM2SC_TOF = 0;                       // clear overflow flag  TPM2SC_TOF = 0;                       // clear overflow flag  TPM2C1SC_CH1F = 0;                    // clear event flag    while(TPM2C1SC_CH1F==0)               // waiting first capture             {    __RESET_WATCHDOG();                 /* kicks the dog */    if(TPM2SC_TOF)                      // timer overflow before capture      return 0;                         // no AC line  }  value1 = TPM2C1V;                     // save first value  TPM2SC_TOF = 0;                       // clear overflow flag  TPM2C1SC_CH1F = 0;                    // clear event flag  while(TPM2C1SC_CH1F==0)               // waiting 2nd capture  {    __RESET_WATCHDOG();                 /* kicks the dog */    if(TPM2SC_TOF)                      // if timer overflow      if(++cpt_tof >= 2)                // if 2 consecutive overflow        return 0;                       // no AC line  }  value2 = TPM2C1V;                     // save first value  value2 = value2 - value1;    if(value2 >= HZ_50_L && value2 <= HZ_50_H)    return 50;                          // for 50 Hz  if(value2 >= HZ_60_L && value2 <= HZ_60_H)    return 60;                          // for 60 Hz  return 0;                             // error  }


Emmanuel

 


0 Kudos

255 Views
bigmac
Specialist III
Hello,

The OP is using the earlier HC908 devices, rather than HCS08.  So the timer module is a TIM, rather than a TPM.  Consequently, the posted code will require some modification to use the HC908.  The TIM register names will differ, and the bit usage within the registers is also likely to differ.

Measuring pulse width using input capture will be relatively simple provided the width never exceeds the TIM overflow period.  If it is possible for the pulse width to exceed the overflow period, the code will be substantially more complex.  Therefore, what range of pulse widths are required to be measured, and what is the expected resolution for the measurement.

Regards,
Mac



Message Edited by bigmac on 2009-02-06 09:51 AM
0 Kudos

255 Views
Nouchi
Senior Contributor II
Hi mac,

You're right, it was only an example to show the way. The TIM module isn't so different than the TPM module.


Emmanuel
0 Kudos