Other Parts Discussed in Thread: MSP430G2553
Hi Everyone ,
I look that are there any exist topic about my question but i could not find
I am working on generating pwm signal by using msp430g2553 . During wathcing the signal on oscilloscope , I released that , After the every 2 ms , The pin becomes high during 2.1ms . According to me , It should not happen . What is the problem ?
Thank you
#include <msp430.h>
#include <stdint.h>
void pwm_init(void){
TA1CTL = TASSEL_2; // TimerA1 SMLCK
TA1CCTL1 = OUTMOD_7 | CCIE; // The output is reset when the timer counts to the TACCRx value. It is set when the timer counts to the TACCR0 value.
TA1CCR1 = 0;
}
void pwm_start(void){
TA1CTL |= MC_1;
}
void pwm_stop(void){
TA1CTL = MC_0; // pwm is stopped by setting to zero pwm bandwidth
}
void pwm_set_duty(uint16_t frequency,int16_t rate){ // rate = percentage of duty cycle
TA1CCR0 = frequency;
pwm_start();
if(rate >= 100) // Rate must be in range of 0,100 .this algrotihm keeps the rate in valid interval
TA1CCR1 = 100;
else if(rate <= 0 ){
pwm_stop();
TA1CCR1 = 0;
}
else
rate%=100;
rate*=frequency;
TA1CCR1 = rate - 1;
}
void main(void){
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
P2DIR |= BIT1;
P2SEL |= BIT1;
pwm_init();
pwm_start();
while(1){
pwm_set_duty(1000,100);
}
}
