AnsweredAssumed Answered

S08MP16 FTM,Stop3 Help

Question asked by Carlos Omar Haro Cordero on Dec 16, 2014
Latest reply on Dec 17, 2014 by Carlos Omar Haro Cordero

Hello Dears

 

I'm working with S08 microprocesor

 

I have the next code lines, I'm trying to following the RM but its hard for me.

 

I need use stop mode (stop3) and then wake up via reset.  I'm not sure if the Internal reference clock is 50Mhz or is 25Mhz

Use a PWM at 60Hz for set a intensity to a led

 

#define OVFCOUNT 50 extern unsigned char count = OVFCOUNT; //number of Timer Overflows before increasing the pulse-width   extern unsigned char updown = OVFCOUNT;         //0 for up, 1 for down   void MCU_Init(void)   {   //Crucial (Stop mode configuration)   SOPT1=0x20; //STOPE=1 to SOPT1 register to enable stop instruction   SPMSC1=0x0; //Set to STOP3 without LVD and BDM modes, see table 3.1 on reference manual for more information //SPMSC2=0x1; //Uncomment this line for set to STOP2.   // System Clock Init   ICSC1=0x44;  //Internal reference selected (50Mhz)   ICSC2=0xC0;  // bus clock  to 6.25Mhz (50Mhz/8)    } void configureMTIM(void) {   ////////////////////////////////////////////////////////////////////////////////////   // formula time =((clock divider)*(MTIMMOD register value+1))/BUS clock ///   //////////////////////////////////////////////////////////////////////////////////   MTIMCLK = 0x08;  //  Bus clock (BUSCLK) witch is 6.25Mhz ,  Bus clock 256 divider    MTIMMOD = 0x30; /* Count to 48 ,+1 */   //time 2.007 ms , ((bus clock divider)*(MTIMMOD+1))/busclock "bus clock =6.250mhz" }  void FTM_Init(void) {   //16-bit counter  max:65536 so i cant get a 60Hz in this way    // TPM clock = BUSCLK = 6.25MHz,channel operate in edge-aligned, Overflow Interrupt Enabled   FTM1SC = FTM1SC_CLKSA_MASK | FTM1SC_TOIE_MASK;      //PWM frequency = 60 Hz   FTM1MOD = 375000000;  // TPMclock/TPMxMOD = 6.25MHz/375000000= 60 Hz    // Configure channel 0 to PWM mode (high-true pulses)     FTM1C0SC = FTM1C0SC_ELS0B_MASK | FTM1C0SC_MS0B_MASK;    // Pulse Width   FTM1C0V = 187500000; // PMxMOD/TPMxCnV = 375000000/187500000, channel 0 set to 50% } interrupt VectorNumber_Vftm1ovf void FTM1ovfISR (void) {   // The same problem un FTM_Init cause the 16-bit counter   //Clear interrupt flag   (void)FTM1SC;   FTM1SC_TOF = 0;      count--;   if (!count)   {          if (!updown) //up counting     {       FTM1C0V += 3750000;       if (FTM1C0V == 371250000) updown = 1;       //when reaching 99%, change to down counting     }      else      {       FTM1C0V -= 3750000;       if (FTM1C0V == 3750000) updown = 0;       //when reaching 1%, change to up counting     }              count = OVF_COUNTS;       } }   }

 

 

I really appreciate your time, thanks for the help

Outcomes