0% found this document useful (0 votes)
142 views2 pages

msp430 2 PWM & 2 Adc

This code configures two PWM outputs and two ADC inputs on an MSP430 microcontroller. It takes continuous ADC samples from two channels and calculates the average of the last 10 samples for each channel. These averages are then output on the corresponding PWM channels to create an analog output representing the input voltage levels. The ADC interrupt handler simply clears the CPUOFF flag to exit low power mode.

Uploaded by

3f84
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
142 views2 pages

msp430 2 PWM & 2 Adc

This code configures two PWM outputs and two ADC inputs on an MSP430 microcontroller. It takes continuous ADC samples from two channels and calculates the average of the last 10 samples for each channel. These averages are then output on the corresponding PWM channels to create an analog output representing the input voltage levels. The ADC interrupt handler simply clears the CPUOFF flag to exit low power mode.

Uploaded by

3f84
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 2

//2 pwm && 2 adc

#include <msp430g2452.h>
volatile int res [2]={0};
long c=0,prom=0, suma=0;
long c1=0,prom1=0, suma1=0;
void main(void){
WDTCTL = WDTPW + WDTHOLD; // watchdog timer setup
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF){
while(1); // If cal constants erased,
} // trap CPU!!
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
P1DIR |= 0x14; // P1.2 &1.4= output
P1SEL |= 0X14; // P1.2&1.4 = TA0.1& TA0.2 output
P1SEL2 |=0X10;
CCR0 = 1024-1;
TACCTL1 = OUTMOD_7;
TACCTL2 = OUTMOD_7;
TACTL = TASSEL_2 + MC_1;

// PWM Period
// TACCR1 reset/set
// TA0CCR2 reset/set
// SMCLK, upmode

ADC10CTL1 = INCH_1+ CONSEQ_1+ADC10DIV_3+ADC10SSEL_0; //Convierte secuencia de


canales A1/A0.
//ADC10 CLOCK DIVIDER
//ADC10 SOUCE CLOCK SELE
CT OSC
ADC10CTL0 = ADC10SHT_3 +MSC+ ADC10ON + ADC10IE;
// ADC10 SAMPLE & HOLD TIME 6
4X ADC10CLKs
__delay_cycles(40);
ADC10AE0 = 0x03;
// Habilita entrada analogic
a
ADC10DTC1 = 0x02;
//Numero de converciones
while(1){
ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY);
ve
ADC10SA = (int)&res[0];
ADC10CTL0 |= ENC + ADC10SC;
ady
__bis_SR_register(CPUOFF + GIE);
xit
_NOP();
_NOP();
suma +=res[0]; c++;
if(c>=10){
prom=suma/10;
CCR1=prom;
prom=0;
suma=0;
c=0;}
suma1 +=res[1]; c1++;
if(c1>=10){
prom1=suma1/10;
CCR2=prom1;

// Wait if ADC10 core is acti


// Data buffer start
// Sampling and conversion re
// LPM0, ADC10_ISR will force e
// space for debugger
// Set Breakpoint here to read ADC

prom1=0;
suma1=0;
c1=0;}
}
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void) {
__bic_SR_register_on_exit(CPUOFF);}

You might also like