Hello, I am Sky.
I am struggling with implementing an ADC function on TM4C123.
I would like to make an ADC function which satisfies four conditions:
1) acquire two channels of ADC signals from ADC0_BASE, ADC1_BASE concurrently
2) synchronize with specific sampling rate (e.g., 200khz) using TIMER (not PWM)
3) use oversampling (4x) mode and calculate average values of them
4) use differential mode
Fortunately, I found well-defined two documents as below:
Ref 1. ADC Oversampling Techniques for Stellaris® Family Microcontrollers
(http://www.ti.com/lit/an/spma001a/spma001a.pdf)
Ref 2. C:\ti\TivaWare_C_Series-2.1.3.156\examples\peripherals\adc\differential.c
They gives me information on oversampling(4x), average values, and differential mode well.
However, I faced with a few questions,
Q1) My program hangs on ADCIntStatus command.
When I write the code on Ref 2,
it hangs on a line "while(!ADCIntStatus(ADC0_BASE, 3, false))".
I don't know how to fix it.
Q2) How can I manipulate sampling time of ADC using Timer?
In order to synchronize with Timer0 (not PWM), I used this command.
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
(When I refer to another manual which named "TivaWare™ Peripheral Driver Library", it explains that
"ADC_TRIGGER_TIMER - A trigger generated by a timer; configured with TimerControlTrigger().")
And then, I follow an example of 5 page of (Ref 1).
However, it seems that defined sampling rate of the Timer doesn't work.
How can I run ADC conversion with desired sampling rate which is defined by Timer?
For better understanding of my problem, I would like to attach my source code below:
=====================================================================
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
uint32_t sequence_number = 3;
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3 | GPIO_PIN_2);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0))
{
}
SysCtlDelay(10);
ADCIntEnable(ADC0_BASE, sequence_number);
ADCSequenceDisable(ADC0_BASE, sequence_number);
ADCSequenceConfigure(ADC0_BASE, sequence_number, ADC_TRIGGER_TIMER, 0);
ADCSoftwareOversampleConfigure(ADC0_BASE, sequence_number, 4);
ADCSoftwareOversampleStepConfigure(ADC0_BASE, sequence_number, 0, (ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END));
ADCSequenceEnable(ADC0_BASE, sequence_number);
ADCIntEnable(ADC0_BASE, sequence_number);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0))
{
}
SysCtlDelay(10);
TimerConfigure(TIMER0_BASE, TIMER_CFG_B_PERIODIC);
TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet() / 1000);
TimerEnable(TIMER0_BASE, TIMER_A);
while(1)
{
ADCProcessorTrigger(ADC0_BASE, sequence_number);
while(!ADCIntStatus(ADC0_BASE, sequence_number, false))
{
}
uint32_t g_ulAverage;
ADCSoftwareOversampleDataGet(ADC0_BASE, sequence_number, &g_ulAverage, 4);
GPIO_toggle(Board_LED0);
}
=====================================================================
Please give me a solution.
Thanks in advance.
-Sky
+ Nov 16, 2016
As Amit Ashara suggested, I will update my posting after remove ADCProcessorTrigger command.