Hi
I am using Tm4C123 launch pad, now i want to use ADC with four channels. I done some code related for this, but it not working fine.
Please anybody help to solve this issue. Any body post Sample program means better
I am posted my code in this i used only two ports
#include <stdbool.h>
#include <stdint.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "driverlib/uart.h"
#include "driverlib/adc.h"
#include "utils/uartstdio.h"
volatile unsigned long delay;
unsigned long test_time1;
//*****************************************************************************
//
// Configure Timer0B as a 16-bit periodic counter with an interrupt every 1ms.
//
//*****************************************************************************
unsigned int adc_value[4];
int main(void)
{
adc_value[0] = 0;
adc_value[1] = 0;
adc_value[2] = 0;
adc_value[3] = 0;
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
// The ADC0 peripheral must be enabled for use.
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 1);
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END);
// Since sample sequence 3 is now configured, it must be enabled.
//
ADCSequenceEnable(ADC0_BASE, 3);
ADCSequenceEnable(ADC0_BASE, 2);
// Clear the interrupt status flag. This is done to make sure the
// interrupt flag is cleared before we sample.
ADCIntClear(ADC0_BASE, 3);
ADCIntClear(ADC0_BASE, 2);
while(1)
{
// Trigger the ADC conversion.
ADCProcessorTrigger(ADC0_BASE, 3);
// Wait for conversion to be completed.
while(!ADCIntStatus(ADC0_BASE, 3, 0))
{
}
ADCSequenceDataGet(ADC0_BASE, 3, &adc_value[3]);
ADCProcessorTrigger(ADC0_BASE, 2);
// Wait for conversion to be completed.
while(!ADCIntStatus(ADC0_BASE, 3, 0))
{
}
ADCSequenceDataGet(ADC0_BASE, 2, &adc_value[2]);
test_time1 = 100;
while(test_time1 > 1)
{
test_time1--;
delay = 100;
while(delay > 1)
delay--;
}
}
}
with regards
Yuvaraj
