//***************************************************************************** // //! Initializes the ADC control routines. //! //! This function initializes the ADC module and the control routines, //! preparing them to monitor currents and voltages on the motor drive. //! //! \return None. // //***************************************************************************** void ADCInit(void) { // // Set the speed of the ADC to 1 million samples per second. // SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS); // // Configure sample sequence zero to capture all three motor phase // currents, the DC bus voltage, and the internal junction temperature. // The sample sequence is triggered by the signal from the PWM module. // ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PWM0, 0); ADCSequenceStepConfigure(ADC0_BASE, 0, 0, PIN_I_PHASEU); ADCSequenceStepConfigure(ADC0_BASE, 0, 1, PIN_I_PHASEV); ADCSequenceStepConfigure(ADC0_BASE, 0, 2, PIN_I_PHASEW); ADCSequenceStepConfigure(ADC0_BASE, 0, 3, PIN_VSENSE); ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_END | ADC_CTL_IE | ADC_CTL_TS); // // Enable sample sequence zero and its interrupt. // ADCSequenceEnable(ADC0_BASE,0); ADCIntEnable(ADC0_BASE, 0); IntEnable(INT_ADC0SS0); }
// ADC初始化 void adc_init(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC); //使能ADC模块 SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS); //设置ADC采样速率 ADCSequenceDisable(ADC_BASE, 0); // 配置前先禁止采样序列 ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_PROCESSOR, 0); //配置ADC采样序列的触发事件和优先级:ADC基址,采样序列编号,触发事件,采样优先级 ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_END | ADC_CTL_CH0 | ADC_CTL_IE); //配置ADC采样序列发生器的步进 :ADC基址,采样序列编号,步值,通道设置 intConnect(INT_ADC0, ADC_Sequence_0_ISR, 0u); ADCIntEnable(ADC_BASE, 0); //使能ADC采样序列的中断 // IntEnable(INT_ADC0); // 使能ADC采样序列中断 intEnable(INT_ADC0); IntMasterEnable(); // 使能处理器中断 ADCSequenceEnable(ADC_BASE, 0); // 使能一个ADC采样序列 the_lock = semBCreate(0); // printf("%x\n", the_lock); }
void Init_ADC() { SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS); ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH0); ADCSequenceEnable(ADC_BASE, 0); ADCProcessorTrigger(ADC_BASE, 0); }
void AdcInit() { SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS); ADCSequenceDisable(ADC0_BASE, 1); ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END); // ADCIntEnable(ADC0_BASE, 1); // IntEnable(INT_ADC0SS1); ADCSequenceEnable(ADC0_BASE, 1); ADCProcessorTrigger(ADC0_BASE, 1); }
//============================================================================// //== ADC初始化函数 ==// //============================================================================// //==说明: 对于测试将方波滤波成为正弦波的测试,需要改变AD的采样频率 ==// //== SYSCTL_ADCSPEED_1MSPS // 采样速率:1M次采样/秒 ==// //== SYSCTL_ADCSPEED_500KSPS // 采样速率:500K次采样/秒 ==// //== SYSCTL_ADCSPEED_250KSPS // 采样速率:250K次采样/秒 ==// //== SYSCTL_ADCSPEED_125KSPS // 采样速率:125K次采样/秒 ==// //== 频率高的方波AD采样频率应适当增加 ==// //==入口参数: 无 ==// //==出口参数: 无 ==// //==返回值: 无 ==// //============================================================================// void ADCInit(void) { SysCtlPeriEnable(SYSCTL_PERIPH_ADC); // 使能ADC模块 SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS); // 设置ADC采样速率 ADCSequDisable(ADC_BASE, 0); // 配置前先禁止采样序列 // 采样序列配置:ADC基址,采样序列编号,触发事件,采样优先级 ADCSequConfig(ADC_BASE, 0, ADC_TRIGGER_PROCESSOR, 0); // 采样步进设置:ADC基址,采样序列编号,步值,通道设置(ADC0转换完后停止触发中断) ADCSequStepConfig(ADC_BASE, 0, 0, ADC_CTL_CH0 | ADC_CTL_END | ADC_CTL_IE); ADCIntEnable(ADC_BASE, 0); // 使能ADC中断 IntEnable(INT_ADC0); // 使能ADC采样序列中断 ADCIntRegister(ADC_BASE, 0, ADC_ISR); IntMasterEnable( ); // 使能处理器中断 ADCSequEnable(ADC_BASE, 0); // 使能采样序列 }
int main(void) { /*SysCtlClockSet( SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);*/ SysCtlClockSet( SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); //20MHz SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); // GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0); GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_0); Init_Timer_a(); Init_Timer_b(); Init_PWM(); unsigned long ulValue; // // Enable the first sample sequence to capture the value of channel 0 when // the processor trigger occurs. // SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC); //Will use ADC ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH0); ADCSequenceEnable(ADC_BASE, 0); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS); // // Trigger the sample sequence. // ADCProcessorTrigger(ADC_BASE, 0); // // Wait until the sample sequence has completed. // while (!ADCIntStatus(ADC_BASE, 0, false)) { } // // Read the value from the ADC. // ADCSequenceDataGet(ADC_BASE, 0, &ulValue); while (1) { } }
void initializeMeasureTask() { #if DEBUG RIT128x96x4Init(1000000); #endif // Load data memory data.temperatureRaw = &(global.temperatureRaw); data.systolicPressRaw = &(global.systolicPressRaw); data.diastolicPressRaw = &(global.diastolicPressRaw); data.pulseRateRaw = &(global.pulseRateRaw); data.measureSelect = &(global.measurementSelection); SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_250KSPS); //setup for temperature sensor ADCSequenceDisable(ADC0_BASE, 1); ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 1); ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_TS); ADCSequenceEnable(ADC0_BASE, 1); /* Interrupt setup * Note: using statically registered interrupts, because they're faster * this means we aren't using the dynamic GPIOPortIntRegister() function, * instead, an entry in the interrupt table is populated with the address * of the interrupt handler (under GPIO Port A) and this is enabled with * IntEnable(INT_GPIOA) */ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Set PA4 as input GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_4); // Enable interrupts on PA4 GPIOPinIntEnable(GPIO_PORTA_BASE, GPIO_PIN_4); // Set interrupt type GPIOIntTypeSet(GPIO_PORTA_BASE, GPIO_PIN_4, GPIO_RISING_EDGE); // Enable interrupts to the processor. IntMasterEnable(); // Enable the interrupts. IntEnable(INT_GPIOA); }
void Init_ADC() { /**** ADC0 ***/ SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS); ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH0); ADCSequenceEnable(ADC_BASE, 0); ADCProcessorTrigger(ADC_BASE, 0); //값읽기 ADCProcessorTrigger(ADC_BASE, 0); while (!ADCIntStatus(ADC_BASE, 0, false)) ; ADCSequenceDataGet(ADC_BASE, 0, &ADC_resultValue0); /**** ADC1 ***/ ADCSequenceConfigure(ADC_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC_BASE, 1, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH1); ADCSequenceEnable(ADC_BASE, 1); ADCProcessorTrigger(ADC_BASE, 1); //값 읽기 ADCProcessorTrigger(ADC_BASE, 1); while (!ADCIntStatus(ADC_BASE, 1, false)) ; ADCSequenceDataGet(ADC_BASE, 1, &ADC_resultValue1); /**** ADC2 ***/ ADCSequenceConfigure(ADC_BASE, 2, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC_BASE, 2, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH2); ADCSequenceEnable(ADC_BASE, 2); ADCProcessorTrigger(ADC_BASE, 2); //값 읽기 ADCProcessorTrigger(ADC_BASE, 2); while (!ADCIntStatus(ADC_BASE, 2, false)) ; ADCSequenceDataGet(ADC_BASE, 2, &ADC_resultValue2); }
void adc_init(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); //Set what the timer runs to TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet() / FREQ ); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_1); SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS); ADCSequenceDisable(ADC0_BASE, 1); ADCSequenceConfigure(ADC_BASE, 1, ADC_TRIGGER_TIMER, 0); ADCSequenceStepConfigure(ADC_BASE, 1, 0, ADC_CTL_CH0); ADCSequenceStepConfigure(ADC_BASE, 1, 1, ADC_CTL_CH1); ADCSequenceStepConfigure(ADC_BASE, 1, 2, ADC_CTL_CH2); ADCSequenceStepConfigure(ADC_BASE, 1, 3, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 1); ADCIntEnable(ADC0_BASE, 1); TimerEnable(TIMER1_BASE, TIMER_A); //Set timer 1A to trigger the ADC TimerControlTrigger(TIMER1_BASE, TIMER_A, 1); //May be useful: //SysCtlADCSpeedGet(); ADCIntClear(ADC0_BASE, 1); ADCIntEnable(ADC0_BASE, 1); IntEnable(INT_ADC0SS1); }
// ******** OS_Init ************ // initialize operating system, disable interrupts until OS_Launch // initialize OS controlled I/O: serial, ADC, systick, select switch and timer2 // input: none // output: none void OS_Init(void){ DisableInterrupts(); RUNPT=0; // Enable processor interrupts. // //IntMasterEnable(); TIMELORD=0; //initialize the system counter for use with thingies (no shit) SDEBOUNCEPREV = 0; btndown_time = 0; SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); //Init System Clock //Systick Init (Thread Scheduler) //taken care of in OS_Launch // Timers galore! SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, (TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC)); TimerControlTrigger(TIMER0_BASE, TIMER_A, true); // TIMELORD Updater TimerControlTrigger(TIMER0_BASE, TIMER_B, true); // ADC_Collect Timer TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()/1000); TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT); IntEnable(INT_TIMER0A); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC); TimerControlTrigger(TIMER1_BASE, TIMER_A, true); // Periodic Timer 1 TimerControlTrigger(TIMER1_BASE, TIMER_B, true); // Periodic Timer 2 TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); TimerIntEnable(TIMER1_BASE, TIMER_TIMB_TIMEOUT); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC); TimerControlTrigger(TIMER2_BASE, TIMER_A, true); // Periodic Timer 3 TimerControlTrigger(TIMER2_BASE, TIMER_B, true); // Periodic Timer 4 TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); TimerIntEnable(TIMER2_BASE, TIMER_TIMB_TIMEOUT); // Init ADC Stuff SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS); // Init Debugging LED SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0); //Semaphores, OS Stuff OS_InitSemaphore(&oled_free,1); OS_InitSemaphore(&OSMailBoxSema4,0); OS_MailBox_Init(); //UART & OLED UARTInit(); RIT128x96x4Init(1000000); //Init OLED //RIT128x96x4StringDraw("Hello World", 0, 12, 15); //ADC ADC_Init(); // Init ADC to run @ 1KHz //Eval Buttons SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_1); GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_1, GPIO_FALLING_EDGE); GPIOPinIntClear(GPIO_PORTE_BASE, GPIO_PIN_1); GPIOPinIntEnable(GPIO_PORTE_BASE, GPIO_PIN_1); IntEnable(INT_GPIOE); //SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1); GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_FALLING_EDGE); GPIOPinIntClear(GPIO_PORTF_BASE, GPIO_PIN_1); GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_1); IntEnable(INT_GPIOF); /* This works for now, but Stellarisware Function owuld be nice */ /*SYSCTL_RCGC2_R |= 0x00000020; // (a) activate port F // delay = SYSCTL_RCGC2_R; //delay, cause i said so GPIO_PORTF_DIR_R &= ~0x02; // (c) make PF1 in GPIO_PORTF_DEN_R |= 0x02; // enable digital I/O on PF1 GPIO_PORTF_IS_R &= ~0x02; // (d) PF1 is edge-sensitive GPIO_PORTF_IBE_R &= ~0x02; // PF1 is not both edges GPIO_PORTF_IEV_R &= ~0x02; // PF1 falling edge event GPIO_PORTF_ICR_R = 0x02; // (e) clear flag4 GPIO_PORTF_IM_R |= 0x02; // (f) arm interrupt on PF1 NVIC_PRI7_R = (NVIC_PRI7_R&0xFF00FFFF)|(0<<21); // (g) priority (shifted into place) (will get set in OS_AddButtonTask) NVIC_EN0_R |= 0x40000000; // (h) enable interrupt 2 in NVIC //dont enable interrupts GPIO_PORTF_PUR_R |= 0x02; //add pull up resistor, just for shits and giggles */ }
// ******** OS_Init ************ // initialize operating system, disable interrupts until OS_Launch // initialize OS controlled I/O: serial, ADC, systick, select switch and timer2 // input: none // output: none void OS_Init(void){ DisableInterrupts(); RUNPT=0; JitterInit(); deleteme=0; // Enable processor interrupts. // //IntMasterEnable(); TIMELORD=0; //initialize the system counter for use with thingies (no shit) NUMBLOCKEDTHREADS=0; TOTALNUMTHREADS=0; SDEBOUNCEPREV = 0; btndown_time = 0; SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); //Init System Clock //Systick Init (Thread Scheduler) //taken care of in OS_Launch // Timers galore! SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, (TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC)); //TimerControlTrigger(TIMER0_BASE, TIMER_A, false); // TIMELORD Updater //TimerControlTrigger(TIMER0_BASE, TIMER_B, true); // ADC_Collect Timer TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()/1000); TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT); TimerEnable(TIMER0_BASE, TIMER_BOTH); IntEnable(INT_TIMER0A); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC); TimerControlTrigger(TIMER1_BASE, TIMER_A, true); // Periodic Timer 1 TimerControlTrigger(TIMER1_BASE, TIMER_B, true); // Periodic Timer 2 TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); TimerIntEnable(TIMER1_BASE, TIMER_TIMB_TIMEOUT); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC); TimerControlTrigger(TIMER2_BASE, TIMER_A, true); // Periodic Timer 3 TimerControlTrigger(TIMER2_BASE, TIMER_B, true); // Periodic Timer 4 TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); TimerIntEnable(TIMER2_BASE, TIMER_TIMB_TIMEOUT); // Init ADC Stuff SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS); // Init Debugging LED SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0); //Semaphores, OS Stuff OS_InitSemaphore(&oled_free,1); OS_InitSemaphore(&OSMailBoxSema4,0); OS_MailBox_Init(); //UART & OLED UARTInit(); RIT128x96x4Init(1000000); //Init OLED //RIT128x96x4StringDraw("Hello World", 0, 12, 15); //ADC ADC_Init(); // Init ADC to run @ 1KHz //Select Switch (button press) Init (select switch is PF1) (pulled from page 67 of the book and modified for PF1...i think) //SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); /*GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1); IntEnable(INT_GPIOF); //IntPrioritySet(INT_GPIOF, 0x00); GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_BOTH_EDGES); GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_1);*/ //NVIC_EN0_R |= 0x40000000; // (h) enable interrupt 2 in NVIC (Not sure what Stellarisware function replaces this) /* This works for now, but Stellarisware Function owuld be nice */ SYSCTL_RCGC2_R |= 0x00000020; // (a) activate port F // delay = SYSCTL_RCGC2_R; //delay, cause i said so GPIO_PORTF_DIR_R &= ~0x02; // (c) make PF1 in GPIO_PORTF_DEN_R |= 0x02; // enable digital I/O on PF1 GPIO_PORTF_IS_R &= ~0x02; // (d) PF1 is edge-sensitive GPIO_PORTF_IBE_R &= ~0x02; // PF1 is not both edges GPIO_PORTF_IEV_R &= ~0x02; // PF1 falling edge event GPIO_PORTF_ICR_R = 0x02; // (e) clear flag4 GPIO_PORTF_IM_R |= 0x02; // (f) arm interrupt on PF1 NVIC_PRI7_R = (NVIC_PRI7_R&0xFF00FFFF)|(0<<21); // (g) priority (shifted into place) (will get set in OS_AddButtonTask) NVIC_EN0_R |= 0x40000000; // (h) enable interrupt 2 in NVIC //dont enable interrupts GPIO_PORTF_PUR_R |= 0x02; //add pull up resistor, just for shits and giggles /* SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable GPIOF GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1); // make Pin 1 an Input GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1); // */ //TODO: i have no f*****g clue what to do here... return; }
int main(void) { unsigned long ulPeriod = 0; //Period for Timer0 //Enable all required peripherals PortFunctionInit(); //Enable console communication with UART UARTStdioInit(0); //Set system clock to 40 MHz SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); /* * * Timer Configuration * */ //Configure timer to be periodic (counts down and then resets) TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); //Calculate period for a pin toggle freq of 1MHz with 50% duty cycle ulPeriod = (SysCtlClockGet() / 10) / 2; TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod - 1); /* * * ADC0 Configuration * */ //Set the ADC sample rate to 500 KSPS SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS); //Disable ADC0 sequencer 3 (so that we can configure it) ADCSequenceDisable(ADC0_BASE, 3); //Disable ADC1 sequencer 3 (so that we can configure it) ADCSequenceDisable(ADC1_BASE, 3); //Configure ADC0 sequencer 3 to trigger based on TIMER0A ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0); //Configure ADC1 sequencer 3 to trigger based on TIMER0A ADCSequenceConfigure(ADC1_BASE, 3, ADC_TRIGGER_TIMER, 0); //Configure the ADC0 to flag the interrupt flag when it finishes sampling ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0|ADC_CTL_END|ADC_CTL_IE); //Configure the ADC1 to flag the interrupt flag when it finishes sampling ADCSequenceStepConfigure(ADC1_BASE, 3, 0, ADC_CTL_CH1|ADC_CTL_END|ADC_CTL_IE); //Enable ADC0 sequencer 3 ADCSequenceEnable(ADC0_BASE, 3); //Enable ADC1 sequencer 3 ADCSequenceEnable(ADC1_BASE, 3); //Enable ADC0 interrupt, it's redundant with line 80 but has to be done ADCIntEnable(ADC0_BASE, 3); //Enable ADC1 interrupt, it's redundant with line 89 but has to be done ADCIntEnable(ADC1_BASE, 3); //Enable timer TimerEnable(TIMER0_BASE, TIMER_A); //Configure TIMER0A to be the ADC sample trigger TimerControlTrigger(TIMER0_BASE, TIMER_A, true); //Clear any interrupts ADCIntClear(ADC0_BASE, 3); ADCIntClear(ADC1_BASE, 3); //Begin sampling ADCIntEnable(ADC0_BASE, 3); ADCIntEnable(ADC1_BASE, 3); //Turn on ADC0 sequence interrupts for sequence 3 IntEnable(INT_ADC0SS3); //Turn on ADC1 sequence interrupts for sequence 3 IntEnable(INT_ADC1SS3); UARTprintf("ADC0 Configured\n"); UARTprintf("ADC1 Configured\n"); //Enable all interrupts IntMasterEnable(); while(1) { } }
int main(void) { unsigned long adc_result[16]; unsigned long cnt; float temperature; // // Set the clocking to run directly from the crystal. // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Configure low-level I/O to use printf() // llio_init(115200); // // Configure ADC // SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS); // ADC sequence #0 - setup with 2 conversions ADCSequenceDisable(ADC_BASE, 0); ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_TIMER, 0); ADCIntRegister(ADC_BASE, 0, ADCIntHandler); ADCIntEnable(ADC_BASE, 0); // sequence step 0 - channel 0 ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_CH0); // sequence step 1 - internal temperature sensor. Generate Interrupt & End of Sequence ADCSequenceStepConfigure(ADC_BASE, 0, 1, ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END); ADCSequenceEnable(ADC_BASE, 0); // // Configure Timer to trigger ADC // SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure( TIMER0_BASE, TIMER_CFG_32_BIT_PER ); TimerControlTrigger(TIMER0_BASE, TIMER_A, true); TimerLoadSet( TIMER0_BASE, TIMER_A, SysCtlClockGet() / 2 ); // 2Hz trigger TimerEnable( TIMER0_BASE, TIMER_A ); printf("\r\n\r\nADC 2 Channel Example\r\n"); // // Loop forever. // while(1) { cnt = ADCSequenceDataGet(ADC_BASE, 0, adc_result); if (cnt == 2) { // Calculate temperature temperature = (2.7 - (float)adc_result[1] * 3.0 / 1024.) * 75. - 55.; printf("%d,%d,%.1f\r\n", adc_result[0], adc_result[1], temperature); } SysCtlSleep(); } }
int main(void) { unsigned long ulADC0_Value[1]; bool running; int LED=2; int i=0; SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); // // Enable GPIO port A which is used for UART0 pins. // TODO: change this to whichever GPIO port you are using. // SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // 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. // TODO: change this to select the port/pin you are using. // GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); // // Select the alternate (UART) function for these pins. // TODO: change this to select the port/pin you are using. // GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); GPIOPinTypeGPIOOutput(LED_PORT, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|TEST_PIN); // Initialize the UART for console I/O. // UARTStdioInit(0); running = false; // // Display the setup on the console. // // UARTprintf("ADC ->\n"); // UARTprintf(" Type: Single Ended\n"); // UARTprintf(" Samples: One\n"); // UARTprintf(" Update Rate: 250ms\n"); // UARTprintf(" Input Pin: AIN0/PE3\n\n"); // >>>>>>>>>>>>> ADC CONFIGURATION <<<<<<<<<<<<<<<<< // Enable the clock to the ADC0 module SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); // >>>>>>>>>>>>> GPI CONFIGURATION <<<<<<<<<<<<<<<<< // Configure the pin as analog input SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); // Configure the ADC to sample at 500KSps SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS); // Disable sample sequences 3 ADCSequenceDisable(ADC0_BASE, 3); // Configure sample sequence 3: timer trigger, priority = 0 ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); // Configure sample sequence 3 steps 0 ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 3); ADCIntEnable(ADC0_BASE, 0); // Clear the interrupt status flag. This is done to make sure the // interrupt flag is cleared before we sample. ADCIntClear(ADC0_BASE, 3); // Sample AIN0 forever. Display the value on the console. while(1) { i++; if (UARTCharsAvail(UART0_BASE)) { char temp; temp = UARTCharGetNonBlocking(UART0_BASE); if (temp == '1') running = true; else if (temp == '0') running = false; } if (running) { if (i==100){ GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, LED); } // Trigger the ADC conversion. ADCProcessorTrigger(ADC0_BASE, 3); // Wait for conversion to be completed. while(!ADCIntStatus(ADC0_BASE, 3, false)) { } // Clear the ADC interrupt flag. ADCIntClear(ADC0_BASE, 3); // Read ADC Value. ADCSequenceDataGet(ADC0_BASE, 3, ulADC0_Value); // Display the AIN0 (PE7) digital value on the console. unsigned short val = ulADC0_Value[0]; UARTCharPut(UART0_BASE,(char)(val&0x00FF)); UARTCharPut(UART0_BASE,(char)((val>>8)&0x00FF)); if (i==200){ GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0); i=0; } } // This function provides a means of generating a constant length // delay. The function delay (in cycles) = 3 * parameter. Delay // 250ms arbitrarily. SysCtlDelay(SysCtlClockGet() / 250); } }