Hello everyone!
I have a challange for all of you MSP pro’s out there. I want to make a PWM of sorts with a 7us pulse width, and a 2.77ms period. Here’s the catch, I need to vary/skip pulses. The “MU” arrays below indicate a 1 when I want a 7us pulse, and a 0 when I skip that pulse.
I am using an MSP430G2452 on a TI launchpad development board. I am a PIC guy, so I am not quite familiar with TI’s MSP430 registers. I’ve been working for hours at this and can’t quite seem to get it. Here’s what I have so far, feel free to markup/dissect/question any parts of my code
-Jameson
#include <MSP430G2452.h>
void ConfigClocks(void);
void ConfigTimerA0(void);
unsigned int PULSE_WIDTH = 20; //60Mu/min pulse is 7us @1MHz, that is 7 counts on timer A2
unsigned int DEAD_TIME = 44208; //dead time after pulse makes 2.77ms
unsigned int MU_80[6] = {1, 0, 0, 0, 0, 0}; //60Mu/min pulse is 7us @8mHz, that is 56 counts on timer A2
unsigned int MU_160[6] = {1, 0, 0, 1, 0, 0};
unsigned int MU_240[6] = {1, 0, 1, 0, 1, 0};
unsigned int MU_320[6] = {1, 1, 0, 1, 1, 0};
unsigned int MU_400[6] = {1, 1, 1, 1, 1, 0};
unsigned int CYCLE_STATE = 0; //to remember which part of the pulse train we are on.
unsigned int BEAM_ON = 0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //stop watchdog timer
P1DIR = BIT0; //P1.0 output
P1OUT = 0;
ConfigClocks();
ConfigTimerA0();
_BIS_SR(GIE); //TURN ON INTERRUPTS!!!
while(1)
{
_NOP();
}
}
void ConfigClocks(void)
{
if(CALBC1_16MHZ == 0xFF || CALDCO_16MHZ == 0xFF)
{
P1OUT = 1;
while(1);
}
BCSCTL1 |= CALBC1_16MHZ; //use 1MHZ calibrated dco
DCOCTL |= CALDCO_16MHZ;
IFG1 &= ~OFIFG;
BCSCTL2 &= ~SELS;
BCSCTL2 |= DIVS0;
}
void ConfigTimerA0(void)
{
CCTL0 = OUTMOD_7 + CCIE;
CCR0 = DEAD_TIME;
TACTL = TASSEL_2 + MC_1 + TAIE;
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0 (void)
{
if(MU_400[CYCLE_STATE] == 1)
{
P1OUT |= BIT0; //led on
CCR1 = PULSE_WIDTH;
}
else
{
P1OUT &= ~BIT0; //led off
CCR1 = 0;
}
CCTL0 &= ~CCIFG;
if(CYCLE_STATE == 5)
{
CYCLE_STATE = 0;
}
else
{
CYCLE_STATE += 1;
}
}