Hi
In University we have a project with the task to set up a simple Class D Audio Amplifier (with PWM Output)
The CPU Hardware is specified: MSP430FG4617 - goal is to get out the most with the given hardware
The first concept is:
- Use the ADC12 to Sample Audio
- Scale and output PWM on TimerB
- calculate a moving average of ADC12 measurements while PWM period (done)
- Update PWM after one period (with Interrupt) (done)
void INIT_ADC(void) //______________________________________________________________________________________
{
P6SEL |= 0x03; // Enable A/D inputs
ADC12CTL0 = SHT0_0 + SHT1_0 + ADC12ON + REFON + REF2_5V + MSC; // S&H 4 ADC12CLK cycles, ADC on, Referenceon, Ref=2,5V, Multiple sample and conversion
ADC12CTL1 = SHP + ADC12SSEL_2 + ADC12DIV_3 + CONSEQ_3; // use sampling timer, MCLK, Divider=4, repeat sequence of channels
ADC12MCTL0 = INCH_0 + SREF_1;
ADC12MCTL1 = INCH_1 + SREF_1;
ADC12MCTL2 = INCH_0 + SREF_1;
ADC12MCTL3 = INCH_1 + SREF_1;
ADC12MCTL4 = INCH_0 + SREF_1;
ADC12MCTL5 = INCH_1 + SREF_1 + EOS;
ADC12IE = 0x08; // Interrupt at MCTL3 - moving average is calculated
ADC12IFG = 0x00;
ADC12CTL0 |= ENC;
_NOP();
_NOP();
ADC12CTL |= ADC12SC;
}
void INIT_PWM(void) //______________________________________________________________________________________
{
// Configure Outputs
P2DIR |= BIT1 + BIT2 // Set Pin 1 and 2 as output
P2SEL |= BIT1 + BIT2 // Selsct Special Function on Pin 1 and 2
TBCTL |= TBIE + MC_1 + TBSSEL_SMCLK +ID0; // Enable Interrupt, Up Mode, SMCLK, Input_Divider=0 -
TBIFG = 0x00;
TBCCTL0 |= CCIE; // Enable Interrupt for CCR0
TBCCR0 = 179; // this is for 8 Mhz - can i get faster?
// Configure Left Chanel PWM
TBCCTL1=OUTMOD7
TBCCR1=0x00
// Configure Right Chanel PWM
TBCCTL2=OUTMOD7
TBCCR2=0x00
}