hi,
for MSP430F1611, I collect samples at 19047 Hz using Timer A
i have a code that collects n number of samples and stores in a ADC12MEM0
All i need to do is to collect the samples in such a way that the 33rd sample is added to the 1st sample 34th to 2nd sample and so on.. and finally an array of 32 samples
how do i read from the memory buffer?you in nadvance
how do i do this calculation..
i have attatched the code that collects all samples to ADC12MEM0
please help me with the code,
//ICC-MSP application builder [F149] : 11/24/2010 3:45:20 PM
//Target 14x device
#include <msp430x16x.h>
#include <msp430def.h>
#include <stdio.h>
#include <math.h>
volatile unsigned int sample[32];
void clock(void)
{
WDTCTL = WDTPW +WDTHOLD; // Stop Watchdog Timer
DCOCTL = DCO0 + DCO1 + DCO2; // Max DCO
BCSCTL1 = RSEL0 + RSEL1 + RSEL2; // XT2on, max RSEL
BCSCTL2 |= SELS; // SMCLK = XT2
while(1)
{
}
}
void port_init()
{
P1OUT=0x00;
P1DIR=0x00;
P1IES=0x00;
P1IE=0x00;
P1SEL=0x00;
P2OUT=0x00;
P2DIR=0x00;
P2IES=0x00;
P2IE=0x00;
P2SEL=0x00;
P3OUT=0x00;
P3DIR=0x00;
P3SEL=0x00;
P4OUT=0x00;
P4DIR=0x00;
P4SEL=0x00;
P5OUT=0x00;
P5DIR=0x00;
P5SEL=0x00;
P6OUT=0x00+BIT2;
P6DIR=0x04;
P6SEL=0x00;
}
void timera_init()
//Clock source=SMCLK
//Divider=1
//TIMACLK=4.0000MHz
//Frequency=19.048KHz ( 52.50uS)
{
TACTL=0x00; //stop timer
//channel0
TACCTL0=0x14;//TAOM0.1,TAOM0.0,TACCIE0,TAOUT0
TACCR0=0xD2;
//channel1
TACCTL1=0x00;
TACCR1=0x00;
//channel2
TACCTL2=0x00;
TACCR2=0x00;
TAR=0x0000;//clear timer counter
TACTL=0x216;//TASSEL.1,TAMC.0,1,TAIE
}
void adc12_init()
{
ADC12CTL0=0x00;
ADC12CTL1=0x616;//SHS.0,SHP,ADC12SSEL.1,CONSEQ.1,CONSEQ.0
ADC12IE=0x8000;
ADC12CTL0=0xFFF2;//SHT1.3,SHT1.2,SHT1.1,SHT1.0,SHT0.3,SHT0.2,SHT0.1,SHT0.0,ADC12MSC,ADC122_5V,ADC12REFON,ADC12ON,ADC12ENC
}
void usart0_init()
//Clock source=SMCLK
//Desired baud=19200
//Actual baud=19196
{
UCTL0=0x10;//CHAR0
UTCTL0=0x20;//SSEL0.1
URCTL0=0x08;//URXEIE0
U0BR1=0x00;
U0BR0=0xD0;
UMCTL0=0xA2;
}
//call this routine to initialise all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
DINT(); //disable all interrupts
ME1=0X00; //disable sfr peripherals
ME2=0X00;
IE1=0x00; //disable sfr interrupts
IE2=0x00;
//watchdog initialisation including nmi function
//WDTCTL=0x5A00 | 0x00;
WDTCTL=0x5A00 | 0x10;//TMSEL
//initialise other peripherals
port_init();
timera_init();
adc12_init();
usart0_init();
clock();
ME1=0xC0;
ME2=0x00;
IE1=0x00;
IE2=0x00;
EINT(); //re-enable interrupts
}
//interrupt handlers
void init_adc12(void)
{
ADC12CTL0=SHT0_15+SHT1_15+ADC12ON+REFON+MSC;
ADC12CTL1=CONSEQ_2+ADC12SSEL_2+ADC12DIV_0+SHP+SHS_1+CSTARTADD_0;
ADC12MCTL0=ADC12MCTL1=ADC12MCTL2=ADC12MCTL3=SREF_1+INCH_9;
ADC12MCTL4=ADC12MCTL5=ADC12MCTL6=ADC12MCTL7=SREF_1+INCH_9;
ADC12MCTL8=ADC12MCTL9=ADC12MCTL10=ADC12MCTL11=SREF_1+INCH_9;
ADC12MCTL12=ADC12MCTL13=ADC12MCTL14=SREF_1+INCH_9;
ADC12MCTL15=SREF_1+INCH_9+EOS; //Vr+=Vref+;//ADC12MEM15 is End Of Sequence
ADC12IE = 0x8000; // Enable ADC12IFG0=>ADC12MEM0 //after 16 sequence conversions ADC12MEM15 sets
ADC12CTL0|=ENC; //Enable conversions
}//end adc12
void init_timera(void)
{
TACCTL0 = OUTMOD_1;
TACCTL0 = CCIE;
TACCR0=0xD2;
TACTL = TASSEL_2 + MC_1;
}
//interrupt handlers
void main(void)
{
init_devices();
init_adc12();
init_timera();
}// end for main
#pragma interrupt_handler timera_0_isr:TIMERA0_VECTOR
void timera_0_isr(void)
{
volatile unsigned int a;
while(1)
{
ADC12CTL0|=ADC12SC;
while ((ADC12IFG & 0x8000)==0); // CHECK FOR CONVERSIONS
sample[a]=ADC12MEM0;//Access results
}
}
thanking you in advance