Hi,
I am working on a simple audio loopback for the CC430F5137.
I want to read the ADC12 @ 8khz en transform the value to PWM as output.
The PWM is made by CCR0 and CCR1 from TA1. the PWM works fine.
The user guide says that the trigger of conversion for the ADC can be derived from the timer.
In my code this does not work. The ADC is never triggered.
initializing of the timer:
PMAPPWD = 0x02D52; //map pwm output to P1.0
P2MAP1 = PM_TA1CCR1A;
PMAPPWD = 0;
TA1CCR0 = 3250-1; //set frequency to 8000khz
TA1CCR1 = 0; //Starting PWM is 0
TA1CCTL1 = OUTMOD_7; //set/reset from CCR1
TA1CTL = TASSEL_2 + MC__UP + TACLR; // SMCLK, stopmode, clear TAR
the value of CCR1 determines the duty cycle of the pwm and should be updated after each conversion of the adc
Initialization of the adc:
P2SEL |= BIT0;
ADC12CTL0 = ADC12ON+ADC12SHT0_2;
ADC12CTL1 = ADC12CONSEQ_2+ADC12DIV_0+ADC12SHS_1+ADC12SSEL_3;
ADC12IE = 0x01;
ADC12CTL0 |=ADC12ENC;
The interrupt vector for the ADC:
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
signed char buf;
switch(__even_in_range(ADC12IV,34))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: // Vector 6: ADC12IFG0
char test = ADC12MEM0;
TA1CCR1 = (test*0.793)-1; // Move results
P3OUT ^= BIT6;
ADC12CTL0 |=ADC12ENC;
break;
case 8: break; // Vector 8: ADC12IFG1
case 10: break; // Vector 10: ADC12IFG2
case 12: break; // Vector 12: ADC12IFG3
case 14: break; // Vector 14: ADC12IFG4
case 16: break; // Vector 16: ADC12IFG5
case 18: break; // Vector 18: ADC12IFG6
case 20: break; // Vector 20: ADC12IFG7
case 22: break; // Vector 22: ADC12IFG8
case 24: break; // Vector 24: ADC12IFG9
case 26: break; // Vector 26: ADC12IFG10
case 28: break; // Vector 28: ADC12IFG11
case 30: break; // Vector 30: ADC12IFG12
case 32: break; // Vector 32: ADC12IFG13
case 34: break; // Vector 34: ADC12IFG14
default: break;
__bis_SR_register(LPM3_bits + GIE);
}
}
Can someone help me with this?