Tool/software: Code Composer Studio
I am using MSP430F5359 with the MSP-TS430PZ100C development tool within CCS and am using the ADC12 module with MSP driver library.
I would like to trigger the ADC12 sampling every 4ms using TimerA and grab 32 samples within that period.
Below is what I have achieved so far and wanted some guidance to drive this further.
#include "driverlib.h"
#define ADCpin GPIO_PORT_P6,GPIO_PIN0 // port 6 pin 0
//---prototypes
void setupADC(void);
//---globals
volatile uint16_t data;
//---main
void main(void)
{
// Stop watch dog timer
WDT_A_hold(WDT_A_BASE);
// ADC setup
setupADC();
while(1)
{
// Start a single conversion, no repeating or sequences.
ADC12_A_startConversion (ADC12_A_BASE, ADC12_A_MEMORY_0, ADC12_A_SINGLECHANNEL);
// Wait for the Interrupt Flag to assert
while(!(ADC12_A_getInterruptStatus(ADC12_A_BASE, ADC12IFG0)));
// Get the value
data = ADC12_A_getResults(ADC12_A_BASE, ADC12_A_MEMORY_0);
// Clear the Interrupt Flag and start another conversion
ADC12_A_clearInterrupt(ADC12_A_BASE,ADC12IFG0);
}
}
//---setup adc
void setupADC(void)
{
// set ADC pin
GPIO_setAsPeripheralModuleFunctionInputPin(ADCpin);
// Initialize the ADC12_A Module
/* Base address of ADC12_A Module
* Use internal ADC12_A bit as sample/hold signal to start conversion
* USE MODOSC 5MHZ Digital Oscillator as clock source
* Use default clock divider of 1
*/
ADC12_A_init(ADC12_A_BASE,
ADC12_A_SAMPLEHOLDSOURCE_SC,
ADC12_A_CLOCKSOURCE_ADC12OSC,
ADC12_A_CLOCKDIVIDER_1);
// setup sampling timer to sample-and-hold for 32 clock cycles
ADC12_A_setupSamplingTimer(ADC12_A_BASE,
ADC12_A_CYCLEHOLD_32_CYCLES,
ADC12_A_CYCLEHOLD_32_CYCLES,
ADC12_A_MULTIPLESAMPLESDISABLE);
//Configure Memory buffer with specified Reference voltages
/* Base address of the ADC12_A Module
* Configure memory buffer 0
* Map input A12 to memory buffer 0
* Vref+ = AVCC (internal)
* Vref- = AVSS
* Memory buffer 0 is not the end of a sequence
*/
ADC12_A_configureMemoryParam param = {0};
param.memoryBufferControlIndex = ADC12_A_MEMORY_0;
param.inputSourceSelect = ADC12_A_INPUT_A0;
param.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
param.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
param.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
ADC12_A_configureMemory(ADC12_A_BASE,¶m);
// switch on the adc12
ADC12_A_enable(ADC12_A_BASE);
//Enable memory buffer 0 interrupt
ADC12_A_enableInterrupt(ADC12_A_BASE,ADC12IE0);
}