EmbeddedRelated.com
Forums

Potentiometer + pwm

Started by felipegazzoni April 12, 2012
Hi, I'm new to MSP430 and would like someone to help me in this problem.

I need to simulate a pwm using a potentiometer connected to a port of the ADC10 but am having trouble creating a routine for stopping TimerA and ADC10_vector. Can anyone help me? It is a very simple problem ...
Thanks
#include "msp430g2231.h"
void ini_ADC10(void);
void ini_TIMERA(void);
void ini_CLOCK(void);
void ini_P1(void);

void main(void)
{
ini_CLOCK();
ini_ADC10();
ini_TIMERA();
ini_P1();

__enable_interrupt();

while(1){
}
}

void ini_ADC10(void)
{

ADC10CTL0 = ADC10SHT0 + ADC10SHT1 + ADC10ON; //
ADC10CTL1 = SHS_0 + ADC10SSEL_0 + CONSEQ_0;
ADC10AE0 = BIT5; // Enable A5 as ADC Input
ADC10CTL1 |= INCH_5; // Disable ADC10
ADC10CTL0 |= ENC;
}

void ini_TIMERA(void)
{
TACCR0 = 999 ; // PWM Period
TACCTL1 = OUTMOD0 + OUTMOD1 + OUTMOD2;
TACCR1 = 0; // CCR1 PWM duty cycle
TACTL = TASSEL_2 + MC_1; // SMCLK, up mode
TACCTL0 = CCIE;
}

void ini_CLOCK(void)
{

BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
BCSCTL2 &= ~(DIVS_3);

}

void ini_P1(void)
{
P1DIR |= BIT6;
P1SEL |= BIT6; //ADC Input pin P15
}

#pragma vector=TIMERA0_VECTOR
__interrupt void TACCR0_RTI(void){

????
}

#pragma vector = ADC10_VECTOR

__interrupt void ADC10_ISR (void) //
Acknowledged automatically

{
ADC10CTL0 |= ADC10SC; // Enable ADC10 and Conversion start
while (ADC10CTL1 & ADC10BUSY); // Wait for ADC Conversion
TACCR1 = ADC10MEM; // Update PWM from new ADC reading
}

Beginning Microcontrollers with the MSP430