Hi
I am new to programming the TM4C micro controller. I am trying to use the TM4C1294 micro controller to read in a 100khz sine wave from a function generator. What should the sampling rate be? Is it twice the the frequency of the 100khz signal? I am currently using a timer interrupt to tell the ADC when to get a reading.
I have attached the code that I currently have but I do not know if I am on the right path. Any help would be appreciated.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/adc.h"
#include "driverlib/timer.h" //TimerConfigure ad TimerLoadSet
#include "driverlib/interrupt.h" //defines and macros for nvic controller interrupt API
#include "inc/tm4c1294ncpdt.h" //definitions fo interrupts and register assignments
int main(void)
{
//uint32_t ui32ACCValues[4];
//volatile uint32_t ui32AccX;
//volatile uint32_t ui32AccY;
//volatile uint32_t ui32AccZ;
uint32_t ui32SysClkFreq;
uint32_t ui32Period;
ui32SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
//getting desired frequency for sampling rate
ui32Period = ui32SysClkFreq/100000/2;
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0|GPIO_PIN_1);
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
TimerLoadSet(TIMER0_BASE, TIMER_A, 40000);
IntEnable(INT_TIMER0A);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
IntMasterEnable();
TimerEnable(TIMER0_BASE, TIMER_A);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 );
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH3);
ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH1|ADC_CTL_IE|ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 1);
while(1)
{
/*ADCIntClear(ADC0_BASE, 1);
ADCProcessorTrigger(ADC0_BASE, 1);
while(!ADCIntStatus(ADC0_BASE, 1, false))
{
}
ADCSequenceDataGet(ADC0_BASE, 1, ui32ACCValues);
ui32AccX = ui32ACCValues[0];
ui32AccY = ui32ACCValues[1];
//ui32AccZ = ui32ACCValues[2];*/
}
}
void Timer0IntHandler(void){
/*TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
if(GPIOPinRead(GPIO_PORTN_BASE, GPIO_PIN_1))
{
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0);
}
else
{
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 2);
}*/
//clear the timer interrupt
uint32_t ui32InputValues[1];
volatile uint32_t ui32Impedance;
// volatile uint32_t ui32AccY;
//volatile uint32_t ui32AccZ;
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
ADCIntClear(ADC0_BASE, 1);
ADCProcessorTrigger(ADC0_BASE, 1);
while(!ADCIntStatus(ADC0_BASE, 1, false))
{
}
ADCSequenceDataGet(ADC0_BASE, 1, ui32InputValues);
ui32Impedance = ui32InputValues[0];
//ui32AccY = ui32ACCValues[1];
//ui32AccZ = ui32ACCValues[2];*/
}