Hi,
I'd like to have a bit generator such as 1010101010000000000 using msp430g2553.
I generated PWM signal using code below. This code will generate about 50-kHz signal with 50% duty cycle.
#include <msp430g2553.h>
unsigned int i=0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= BIT2; // P1.2 to output
P1SEL |= BIT2; // P1.2 to TA0.1
CCR0 = 20-1; // PWM Period
CCTL1 = OUTMOD_7; // CCR1 reset/set
CCR1 = 10; // CCR1 PWM duty cycle
TACTL = TASSEL_2 + MC_1; // SMCLK, up mode
}
But this is only 10101010101010101010 not (1010101010000000000) so I tried to use interrupt and added these lines in the main ().
P1IE |= BIT2; // P1.2 interrupt enabled
P1IES |= BIT2; // P1.2 Hi/lo edge
P1IFG &= ~BIT2; // P1.2 IFG cleared
Also tried to add interrupt service routine such as
#pragma vector = TIMER0_A0_VECTOR
__interrupt void CCR0_ISR(void) {
for (i=0;i<=9;i++){
if (i <= 4) {
CCTL0= OUTMOD_1;
P1IFG &= ~BIT2;
}
else if(i <= 8) {
CCTL0= OUTMOD_0;
P1IFG &= ~BIT2;
}
else {
CCTL0= OUTMOD_0;
P1IFG &= ~BIT2; //clear IFG
i=0; //reset i so it can only loop between 0~9
}
}
}
My code doesn't work either so can you please help me generating bit sequence 10101010100000000000 and repeating these?