Tool/software: Code Composer Studio
Good Evening everybody.
I 'm programming ADC module on TMC123GH6PM and I have some questions about trigger ADC.
My clock system is 57MHz, I want to trigger ADC every 1 minutes. To do that, I load a clock value 3428571428 ( because I am using timer 32bit ).
My application works correctly.
My question is that: how to trigger every 10 minutes?
I have tried to use prescale but it failed. The Prescale Timer didn't work. Here is my code:
//#define TimerOneShot //Timer One Shot is only available for Timer Both
//#define TimerOneShotUp //Timer One Shot Up is only available for Timer16bit
//##########--Include File--#########
#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/adc.h"
//##########--For Variable--########
#define TimeTrigger 3428571428 //It means 2^16
volatile uint32_t ui32MoistureBuffer[8], ui32MoistureAvr,ui32Clock;
volatile float Moisture;
//##########--For ISR--#####
void Moisture_ISR(void)
{
ADCIntClear(ADC0_BASE, 0);
ADCSequenceDataGet(ADC0_BASE, 0,(uint32_t *)&ui32MoistureBuffer);
ui32MoistureAvr= (ui32MoistureBuffer[0]+ ui32MoistureBuffer[1]+ ui32MoistureBuffer[2]+ ui32MoistureBuffer[3]
+ ui32MoistureBuffer[4]+ ui32MoistureBuffer[5]+ ui32MoistureBuffer[6]+ ui32MoistureBuffer[7] + 2)/8;
Moisture= ui32MoistureAvr*(5.0/4096.0);
ui32Clock++;
}
#if defined (TimerOneShot)|| defined (TimerOneShotUp)
void TimerActive(void)
{
#ifdef TimerOneShot
{
TimerLoadSet(TIMER0_BASE, TIMER_BOTH, 19999999);
TimerEnable(TIMER0_BASE, TIMER_BOTH);
while(TimerValueGet(TIMER0_BASE, TIMER_BOTH)!=0)
{};
}
#endif
#ifdef TimerOneShotUp
void TimerActive(void)
{
TimerLoadSet(TIMER0_BASE, TIMER_A, 19999999);
TimerEnable(TIMER0_BASE, TIMER_A);
while(TimerValueGet(TIMER0_BASE, TIMER_A)!=0)
{};
}
#endif
}
#endif
int main(void)
{
/*Clock configure*/
SysCtlClockSet(SYSCTL_SYSDIV_3_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
/*Port Clock configure*/
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
//ADCHardwareOversampleConfigure(ADC0_BASE, 64);
/*Pin configure*/
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
/*ADC configure*/
ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 5, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 6, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 7, ADC_CTL_CH0|ADC_CTL_IE| ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 0);
ADCIntEnable(ADC0_BASE, 0);
IntEnable(INT_ADC0SS0);
IntMasterEnable();
/*Timer Trigger ADC configure*/
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIOD);
TimerPrescaleSet(TIMER0_BASE, TIMER_BOTH,60000);
TimerLoadSet(TIMER0_BASE, TIMER_BOTH,TimeTrigger);
TimerControlTrigger(TIMER0_BASE, TIMER_BOTH,true);
TimerEnable(TIMER0_BASE, TIMER_BOTH);
#ifdef TimerOneShot
TimerConfigure(TIMER0_BASE, TIMER_CFG_A_ONE_SHOT);
#endif
#ifdef TimerOneShotUp
TimerConfigure(TIMER0_BASE, TIMER_CFG_A_ONE_SHOT_UP);
#endif
while(1)
{
//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4);
//ui32Clock=TimerValueGet(TIMER0_BASE, TIMER_BOTH);
//SysCtlDelay(20000000);
//ADCProcessorTrigger(ADC0_BASE, 0);
}
}
Thank and Best Regards.