Part Number: MSP430F6779
So, I would start with why I need two threads to run at the same time. I need to generate SPWM at a particular pin and at the same time keep on checking various ADC values which is directly related to the generated PWM then compute a lot and print those computed values to the LCD screen. I am using this code for SPWM generation and checking ADC values and computation
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
int duty_cycle[]=
{2,4,7,9,11,13,16,18,20,22,24,27,29,31,33,35,38,40,42,44,46,49,51,53,55,57,60,62,64,66,68,70,72,75,77,79,81,83,85,87,89,91,93,96,98,100,102,104,106,108,110,112,11 4,116,118,120,122,124,126,128,129,131,133,135,137,139,141,143,144,146,148,150,152,153,155,157,159,160,162,164,166,167,169,171,172,174,176,177,179,180,182,183,185,186,188,190,191,192,194,195,197,198,200,201,202,204,205,206,208,209,210,211,213,214,215,216,217,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,236,237,238,239,240,240,241,242,243,243,244,244,245,246,246,247,247,248,248,249,249,250,250,251,251,252,252,252,253,253,253,253,254,254,254,254,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,254,254,254,254,253,253,253,253,252,252,252,251,251,250,250,249,249,248,248,247,247,246,246,245,244,244,243,243,242,241,240,240,239,238,237,236,236,235,234,233,232,231,230,229,228,227,226,225,224,223,222,221,220,219,217,216,215,214,213,211,210,209,208,206,205,204,202,201,200,198,197,195,194,192,191,190,188,186,185,183,182,180,179,177,176,174,172,171,169,167,166,164,162,160,159,157,155,153,152,150,148,146,144,143,141,139,137,135,133,131,129,128,126,124,122,120,118,116,114,112,110,108,106,104,102,100,98,96,93,91,89,87,85,83,81,79,77,75,72,70,68,66,64,62,60,57,55,53,51,49,46,44,42,40,38,35,33,31,29,27,24,22,20,18,16,13,11,9,7,4,2,0};
TA0CCR0 |= TIMER_PERIOD;
TA0CCTL2 |= OUTMOD_7;
TA0CTL = TASSEL_2 + MC_1;
while(1)
{
for(int i=0; i<360; i++) //Generate PWM 1
{
//TA0CCR2 = 0;
TA0CCR0 |= TIMER_PERIOD;
TA0CCR2 = duty_cycle[i];
}
ct2=read_adc_values(4);
}
}
float read_adc_values(int array_index)
{
results[array_index] = SD24_B_getResults(SD24_BASE,
array_index);
while(results[array_index]<8392586 || results[array_index]>8430180) // zero crossing detection
{
// count++;
results[array_index] = SD24_B_getResults(SD24_BASE,
array_index);
if(results[array_index]>peak_conversion[array_index])
peak_conversion[array_index]=results[array_index];
rms_value=peak_conversion[array_index]*0.00003973532251036290 - 332.8842284;
}
return rms_value;
}
There are many other things I need to monitor and this is just one ADC value. I need the PWM to be generated throughout the code. Like it should not stop while I am checking various ADC values, doing complex computation and displaying the values on LCD screen even for a second while running the code. What do I do here? I need your help with this. Do I need to implement multi-threading here? Is there any way for continuous PWM generation with variable duty cycle (SPWM)? Like I write a piece of code for generating SPWM at a particular pin and it will generate it throughout the code run-time. Thanks