Hai,
Am using MC9S08SG8 micro controller ,and am using code warrior V6.3 software ,here am using PWM in 7th pin ,
my problem is in output duty cycle first pulse is grater then the other pulse ,like this. plz any one can help me.
Thanks in advance ,
Regards,
karthik
Hi karthik,
I am not familiar with S08 product.
Have you try to select the counter clock source after written duty cycle?
Best Regards,
Robin
thanks a lot ,
can u share a PWM example code, in coed warrior ,any micro controller
Please check the following code
void main(void)
{
SOPT2 = SOPT2_T1CH1PS_MASK | SOPT2_T1CH0PS_MASK;
PTBDD_PTBDD6 = 1; //Pin as output
PTBD_PTBD6 = 0; // PTC1 in Low
PTCDD_PTCDD1 = 1; //Pin as output
PTCD_PTCD1 = 1; // PTC1 in High
// TPM clock = BUSCLK = 8MHz,channel operate in edge-aligned, Overflow Interrupt Enabled
TPM1SC = 0;
// Configure channel 1 High true pulses Edge aligned
TPM1C1SC = TPM1C1SC_ELS1B_MASK | TPM1C1SC_MS1B_MASK;
TPM1C1V = 4000; // channel 1 set to 50%
TPM1SC = TPM1SC_CLKSA_MASK | TPM1SC_TOIE_MASK;
TPM1MOD = 8000; // PWM frequency is about 1 KH
EnableInterrupts;
for(;;)
{
__RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
/**************************************************************************************************/
void interrupt VectorNumber_Vtpm1ovf TPM1ovfISR (void)
{
//Clear interrupt flag
(void)TPM1SC;
TPM1SC_TOF = 0;
PTBD_PTBD6 ^= 1;
}
/**************************************************************************************************/
This is for the S08SH family
If you are using the external clock, maybe you are getting a different time on the first cycle due the clock set up.
I recommend you check the following document
https://www.nxp.com/docs/en/user-guide/HCS08QRUG.pdf
I hope this will help
Thanks a lot ,
Am using the software code warrior V6.3 , MC9S08SG8 8 pin package type and here am attach my sample code ,
this code i have a same problem above mention , 7th pin of controller is pwm am using internal clk.
and this is my code .
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "PWM1.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
unsigned int ADC_RESULT_TOTAL,ADC_RESULT[10],adc_value;
char a,b;
unsigned int ADC();
/* User includes (#include below this line is not maintained by Processor Expert) */
void main(void)
{
/* Write your local variable definition here */
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/
/* Write your code here */
/* For example: for(;;) { } */
PWM1_Disable();
PWM1_ClrValue();
Cpu_Delay100US(1000);
for(;;)
{
setReg16(TPM2MOD, 4076);// period for 407Hz
TPM2C0V =3057; // 75% duty cycle
PWM1_Enable(); // enable the pwm
Cpu_Delay100US(5000); // delay for 50msec
PWM1_Disable(); // disable the pwm
Cpu_Delay100US(5000);
}
/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;){}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
}
thanks for u r reply ,i try this code same problem has occuring.
Thanks