using Tiva launchpad, TM4C123GH6PM
Still learning. Hoping somebody can spot what's wrong. I'm trying to setup a timer to trigger ADC. ADC returns incorrect values.
#define PART_TM4C123GH6PM
#include <stdint.h>
#include <stdbool.h>
#include "stdlib.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_uart.h"
#include "inc/hw_timer.h"
#include "inc/hw_gpio.h"
#include "inc/hw_pwm.h"
#include "inc/hw_types.h"
#include "driverlib/adc.h"
#include "driverlib/timer.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/udma.h"
#include "driverlib/pwm.h"
#include "driverlib/ssi.h"
#include "driverlib/systick.h"
#include "driverlib/adc.h"
#include "utils/uartstdio.h"
#include "utils/uartstdio.c"
#include <string.h>
uint32_t _adc;
uint32_t TempValueC;
void ADCInit(void)
{
// ADC
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlDelay(3);
// GPIO (ADC Pins)
//SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_TIMER, 0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS| ADC_CTL_IE | ADC_CTL_END);
//ADCHardwareOversampleConfigure(ADC0_BASE, 64);
ADCSequenceEnable(ADC0_BASE, 1);
ADCIntEnable(ADC0_BASE, 1);
// Timer (ADC Trigger)
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_A_PERIODIC);
TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet() / 10000); // 10KHz
TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
TimerEnable(TIMER0_BASE, TIMER_A);
IntEnable(INT_TIMER0A);
IntEnable(INT_ADC0SS1);
}
void ADC0SS1IntHandler(void)
{
TimerDisable(TIMER0_BASE, TIMER_A);
// Ack Interrupt
ADCIntClear(ADC0_BASE, 1);
// Read ADC Data
ADCSequenceDataGet(ADC0_BASE, 1, _adc);
TempValueC = (uint32_t)(147.5 - ((75.0*3.3 *(float)_adc)) / 4096.0);
UARTprintf("Temperature = %3d*C: ", TempValueC);
TimerEnable(TIMER0_BASE, TIMER_A);
}
void InitConsole(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTStdioConfig(0, 9600, 16000000);
}
void main(){
InitConsole();
ADCInit();
// Clock (80MHz)
SysCtlClockSet(SYSCTL_SYSDIV_2_5| SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
IntMasterEnable();
while(1){
}
}