hi,
i'm a student from germany, but i'm study supply engineering and didn't learned programming. But i wan't to learn it with books, internet etc. and i have read very much and did most of your workshops, and read very much in forums. but now i have a problem which i can't solve on my own.
i wan't to read the values of the adc into an array. this is no problem with 15 values (array[15]). but then i wan't to make an array with 100 values (array[100]) the code stops by an FaultISR(). and i don't know why.
i wan't to build a fast logger, wich samples at 1000hz and writes the values of the adc first in an array[2000] and after logging (2s logging because 2000 values at 1000Hz==>2s) the values of the array will be send over the uart to the pc
Here's the code (necessary passage yellow colored)
#include "inc/hw_ints.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 the ADC
#include "driverlib/debug.h"
#ifdef DEBUG
void__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
int main(void)
{
unsigned long ulPeriod;
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); //Set the System Clock to 40 MHZ; 16MHZ_XTAL ==>400MHZ PPL / 2 /SYSDIV_5 =40MHZ
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);//enable periphery GPIO port F for rgb led
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);//enable periphery GPIO port E for ADC
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);//enable periphery GPIO port D for ADC
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);//enable periphery GPIO port B for ADC
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); // Set the Pin PB4 to analog input on
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1); // Set the Pin PB4 to analog input on
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_3); // Set the Pin PB4 to analog input on
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_4); // Set the Pin PB4 to analog input on
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); //port F as output; pin 1 2 3 = output
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //enable periphery TIMER 0
TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER); // set TIMER 0 To 32 bit counting down periodic
ulPeriod = (SysCtlClockGet())*10;// ==> 10s
TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod -1); //Set the Count beginning to ulPeriod
IntEnable(INT_TIMER0A); //enable Interrupt on TIMER0A
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); //interrupt then Timer0A = 0
IntMasterEnable(); //enable master interrupt
TimerEnable(TIMER0_BASE, TIMER_A); //enable timer
volatile unsigned long ulTempAvg;
volatile unsigned long ulTempValueC;
volatile unsigned long ulTempValueF;
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); //enable the periphery ADC
SysCtlADCSpeedSet(SYSCTL_ADCSPEED_250KSPS); //set the periphery to 250ksps
ADCHardwareOversampleConfigure(ADC0_BASE, 64); //hardware periphery rate 64 ==> 250/64
ADCSequenceDisable(ADC0_BASE, 1); //disable ADC sequencer 1
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); // processor triggers the adac sequencer 1, with the highest priority 0()
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0); //sequencer 1 samples in first step the temperature sensor (ADC_CTL_TS) change adc_CTL_TS with ADC_CTL_CH0 trough ADC_CTL_CH23 for GPIOS use!!!
ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH2); //sequencer 1 has 4 steps. page 761 spms294e.pdf and page 40 spmu019o
ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH4);
ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_CH10 | ADC_CTL_IE | ADC_CTL_END); //last step; cause an interrupt (ADC_CTL_IE); set as last step of the sequence (ADC_DTL_END)
ADCSequenceEnable(ADC0_BASE, 1); //enable the ADC
unsigned long ulADC0Value[4]; //array for the 4 sequencer data
//int array[1] = { 0 };
int array[100]={0}; //array for test
while(1)
{
ADCIntClear(ADC0_BASE, 1); //clear the ADC0 Interrupt from sequencer 1
ADCProcessorTrigger(ADC0_BASE, 1); //trigger the ADC conversion
while(!ADCIntStatus(ADC0_BASE, 1, false)) //wait for conversion; better to do this with an interrupt!!
{
}
ADCSequenceDataGet(ADC0_BASE, 1, ulADC0Value); //write the values from the 4 steps into the ulADC0Value Array
ulTempAvg = (ulADC0Value[0] + ulADC0Value[1] + ulADC0Value[2] + ulADC0Value[3] + 2)/4; //
ulTempValueC = 33*((2475 * ulTempAvg) / 4096);
array[0]= ulTempAvg;
array[1]= ulTempAvg;
array[2]= ulTempAvg;
array[99]= ulTempAvg;
}
}
void Timer0AIntHandler(void)
{
// Clear the timer interrupt
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
// Read the current state of the GPIO pin and
// write back the opposite state
if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2))
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
}
else
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 14);
}
}