Tool/software: Code Composer Studio
hello all,
i have to find the maximum and minimum value of a continuous ramp pulse with on time of 400 ms and i have to store this minimum and maximum value in a array of 500 index, can any one help me . i am getting 2 sample from adc and comp
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "driverlib/flash.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/pin_map.h"
#include "driverlib/pwm.h"
#include "driverlib/sysctl.h"
#include "utils/ustdlib.h"
#include "utils/uartstdio.h"
//#include "drivers/pinout.h"
#include "inc/tm4c123gh6pm.h"
#include "driverlib/adc.h"
#include "driverlib/timer.h"
///////////// start of declaration/////////////////////////////////
const int sampleFreq = 150000,ref=2240;
uint32_t ADC0Value, present_ADC[5], past_ADC, max_ADC[500],min_ADC[500],System_Clock,present_ADCsample,past_ADCsample;
uint16_t samplePeriod,i;
uint32_t ui32Period,pcount=0,ncount=0,presentmaxvalue_ADC,prevmaxvalue_ADC,presentminvalue_ADC,prevminvalue_ADC,ADC_maxvalue,ADC_minvalue,min;
uint32_t l=0,k=0;
bool status,nextsample;
bool max;
void systemSetup(void);
//void PWM_Enable(void);
void Timer(void);
void ADC(void);
void Interrupt_Enable(void);
////////////// end of declaration//////////////
void systemSetup(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
MAP_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_5);
MAP_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, 0);
System_Clock=SysCtlClockGet(); // 40MHz
status=0;
max=0;
nextsample=0;
}
void ADC0SS3IntHandler(void)
{
past_ADCsample=present_ADCsample;
ROM_ADCSequenceDataGet(ADC0_BASE,3,&ADC0Value);
ROM_ADCIntClear(ADC0_BASE,3);
if(max==0)
{
present_ADCsample=ADC0Value;
if(nextsample)
{
max=1;
status=1;
}
}
nextsample=1;
if(status)
{
if(present_ADCsample>past_ADCsample)
{
// prevmaxvalue_ADC= presentmaxvalue_ADC ;
presentmaxvalue_ADC=present_ADCsample;
// if(presentmaxvalue_ADC>prevmaxvalue_ADC)
// {
ADC_maxvalue=presentmaxvalue_ADC;
// }
past_ADCsample=0;
present_ADCsample=0;
nextsample=0;
max=0;
}
else
{
// prevminvalue_ADC=presentminvalue_ADC ;
presentminvalue_ADC=present_ADCsample;
// min=present_ADCsample;
// if(presentminvalue_ADC<prevminvalue_ADC)
// {
ADC_minvalue=presentminvalue_ADC;
// }
past_ADCsample=0;
present_ADCsample=0;
nextsample=0;
max=0;
}
}
}
void Timer0IntHandler(void)
{
// int i=0;
ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
// l=l+1;
}
void Timer(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
ui32Period = SysCtlClockGet()/sampleFreq; // Interrupts evrey half second
TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period-1);
}
void ADC(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
ADCSequenceDisable(ADC0_BASE, 3);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 3);
}
void Interrupt_Enable(void)
{
IntEnable(INT_TIMER0A);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
IntMasterEnable();
ADCIntEnable(ADC0_BASE, 3);
IntEnable(INT_ADC0SS3);
TimerEnable(TIMER0_BASE, TIMER_A);
TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
}
int main(void)
{
systemSetup();
// PWM_Enable();
Timer();
ADC();
Interrupt_Enable();
while(1)
{
// PWMPulseWidthSet(PWM1_BASE, PWM_OUT_4,200);
}
}
aring them . but i am not getting the result.