Hello All,
I have been working on the following code, and am asking for help with ways to improve and debug it.
1.The switch determines which code will be ran.
2. Program 1 outputs a 5ms x 10ms on P1.2
3. Program 2 outputs P1.1 high for the duration P1.2 is on. P1.1 then goes low for a 500 microseconds and high for 500 micro seconds. P1.2 is high for 2.5 milliseconds, and then runs at 15kHz for 1.5 milliseconds
Any feedback on improvements and getting the following code to work would be greatly appreciated.
//SCR High Side-Low Side driver software for the MSP430F2012. The software is capable of two programs selected by a switch.
//Program 1 outputs a PWM [10ms period,50% duty cycle]on the low side.
//Program 2 outputs a Peak and Hold signal [5ms x 10ms] with high side clamping.
//P1.1 = High Side P1.2 = Low Side
#include <msp430f2012.h>
#include <msp430.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //Stop Watch Dog Timer
//Configure Switch (Choose Program A or B)
//Declares P1.0 input for reading the switch
if(analogRead(P1IN)<0.5) //Program A (Continous 5ms x 10ms on Low Side)
{
BCSCTL1 = CALBC1_1MHZ; //Set range
DCOCTL = CALDCO_1MHZ; //SMCLK = DCO = 1MHz
P1DIR |= (BIT2); //Set P1.2 [Low Side] to output direction
P1SEL |= (BIT2); //Declares TA1 & Turns on High Side
TACTL= MC_1 + TASSEL_2; //Tells CCR0 to count up with SMCLK
TACCTL1=OUTMOD_7; //Sets Set/Reset Mode with TACCR1
TACCR0=10000-1; //Set CCR0 to 100 Hz (10ms Period)
TACCR1=5000; //Sets 50% duty cycle
while(1){} //Runs Continously
}
else // Program B (Peak and Hold)
{
//Step 1 (High Side & Low Side Static for 2.5 ms or by I=1A)
P1OUT = 0; //Initializes P1.0 to off state
P1DIR = BIT1; //Sets P1.1 to output direction
P1DIR = BIT2; //Sets P1.2 to ouput direction
P1OUT |= BIT1; //Turns P1.1 on statically
P1OUT |= BIT2; //Turns P1.2 on statically
_delay_cycles(39745); //2.5 ms hold time
//Step 2 (High Side=Static Low Side=15 kHz)
BCSCTL1 = CALBC1_1MHZ; //Set range
DCOCTL = CALDCO_1MHZ; //SMCLK = DCO = 1MHz
P1DIR |= (BIT2); //Set P1.2 to output direction
P1SEL |= (BIT2); //Declares TA1 & Turns on High Side
TACTL= MC_1 + TASSEL_2; //Tells CCR0 to count up with SMCLK
TACCTL1=OUTMOD_7; //Sets Set/Reset Mode with TACCR1
TACCR0=66-1; //Set CCR0 to 15 kHz (Hold Frequency)
TACCR1=33; //Sets 50% duty cycle
_delay_cycles(23848); //1.5ms hold time
//Step 3 (High side clamp on P1.1)
P1OUT &= ~BIT1; //Turns P1.1 off
P1OUT &= ~BIT2; //Turns P1.2 off
_delay_cycles(8000); //500 microsecond clamp
P1OUT |= BIT1; //Turns P1.1 on
_delay_cycles(8000); //500 microsecond on time
P1OUT &= ~BIT1; //Turns P1.1 off
while(1){}
}
}
