Other Parts Discussed in Thread: SW-DRL
Tool/software: Code Composer Studio
Hi All,
Currently I am facing a problem with ADC input where I am trying to get the input through PE3 which is triggered with timer.
I have built the code without any error though I am not able to trigger the interrupt. and some more problems are pointed in the attached image.
Any suggestion is appriciated.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "driverlib/adc.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
//#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
//#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
float Aquire[1000];
uint32_t ResultIndex = 0;
uint32_t stat;
double fRadians;
float prev = 0;
float strt = 2000;
uint32_t toggler = GPIO_PIN_2;
uint32_t ADC0Value[1];
#ifndef M_PI
#define M_PI 3.14159265358979323846264
#endif
void
InitConsole(void)
{
//UARTprintf("Console start");
//
// Enable GPIO port A which is used for UART0 pins.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
// Configure the pin muxing for UART0 functions on port A0 and A1.
// This step is not necessary if your part does not support pin muxing.
//
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
//
// Enable UART0 so that we can configure the clock.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
//
// Select the alternate (UART) function for these pins.
//
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Initialize the UART for console I/O.
//
UARTStdioConfig(0,115200,16000000);
UARTprintf("Console end\n");
}
void
InitADC0(void)
{
//
// The ADC0 peripheral must be enabled for use.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
//
// For this example ADC0 is used with AIN0 on port E7.
// The actual port and pins used may be different on your part, consult
// the data sheet for more information. GPIO port E needs to be enabled
// so these pins can be used.
// TODO: change this to whichever GPIO port you are using.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
//
// Select the analog ADC function for these pins.
// Consult the data sheet to see which functions are allocated per pin.
// TODO: change this to select the port/pin you are using.
//
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
//
// Enable sample sequence 3 with a processor signal trigger. Sequence 3
// will do a single sample when the processor sends a signal to start the
// conversion. Each ADC module has 4 programmable sequences, sequence 0
// to sequence 3. This example is arbitrarily using sequence 3.
//
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
//
// Configure step 0 on sequence 3. Sample channel 0 (ADC_CTL_CH0) in
// single-ended mode (default) and configure the interrupt flag
// (ADC_CTL_IE) to be set when the sample is done. Tell the ADC logic
// that this is the last conversion on sequence 3 (ADC_CTL_END). Sequence
// 3 has only one programmable step. Sequence 1 and 2 have 4 steps, and
// sequence 0 has 8 programmable steps. Since we are only doing a single
// conversion using sequence 3 we will only configure step 0. For more
// information on the ADC sequences and steps, reference the datasheet.
//
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE |
ADC_CTL_END);
//
// Since sample sequence 3 is now configured, it must be enabled.
//
ADCSequenceEnable(ADC0_BASE, 3);
//
// Clear the interrupt status flag. This is done to make sure the
// interrupt flag is cleared before we sample.
//
ADCIntClear(ADC0_BASE, 3);
UARTprintf("ADC0 end\n");
}
void
InitGPIO_F(void)
{
//
// Enable the GPIO port that is used for the on-board LED.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
//
// Enable the GPIO pins for the LED (PF1 & PF2).
//
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
UARTprintf("GPIOEnabled\n");
}
void
InitTimer(void)
{
// Enable the peripherals used by this example.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
//SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
//
// Enable processor interrupts.
//
IntMasterEnable();
//tickk = SysCtlClockGet();
//
// Configure the two 32-bit periodic timers.
//
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
//ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet());
//ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet() / 2);
//
// Setup the interrupts for the timer timeouts.
//
IntEnable(INT_TIMER0A);
//ROM_IntEnable(INT_TIMER1A);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
//ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
//
// Enable the timers.
//
TimerEnable(TIMER0_BASE, TIMER_A);
//ROM_TimerEnable(TIMER1_BASE, TIMER_A);
UARTprintf("TimerEnabled\n");
}
//*****************************************************************************
//
// The interrupt handler for the first timer interrupt.
//
//*****************************************************************************
void
Timer0IntHandler(void)
{
UARTprintf("Timer start\n");
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
toggler ^= GPIO_PIN_2;
UARTprintf("Toggler = %3d\n",toggler);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2,toggler);
UARTprintf("bulb\n");
ADCIntClear(ADC0_BASE, 3);
UARTprintf("ADCClear\n");
ADCProcessorTrigger(ADC0_BASE, 3);
UARTprintf("ProTrig\n");
while(!ADCIntStatus(ADC0_BASE, 3, false))
{
UARTprintf("G\r");
}
ADCIntClear(ADC0_BASE, 3);
UARTprintf("ADCClear\n");
ADCSequenceDataGet(ADC0_BASE, 3, ADC0Value);
UARTprintf("GetData\n");
//UARTprintf("%3d\n",ADC0Value[0]);
UARTprintf("%3d\n",ADC0Value[0]);
if (prev-ADC0Value[0]>strt)
{
if(stat==0)
{
if(ResultIndex<900)
{
Aquire[ResultIndex] = ADC0Value[0];
ResultIndex+=1;
}
else
{
stat = 1;
}
}
}
else
{
prev = ADC0Value[0];
}
IntMasterDisable();
IntMasterEnable();
}
int main(void)
{
//FPULazyStackingEnable();
//FPUEnable();
//SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
//SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
//
// Initialize the UART and write status.
//
InitConsole();
//
// Initialize the ADC0.
//
InitADC0();
InitGPIO_F();
//
// Initialize the Timer for triggering.
//
InitTimer();
while(1)
{
}
}