Browse files

ADCRead works. ADC_Collect might need more attention.

Signed-off-by: Cruz Monrreal II <Cruz.Monrreal@gmail.com>
  • Loading branch information...
1 parent 9e7b17d commit 9b47a695f1c1bd2a0642ed3f2e04648c3bc574ec @cmonr cmonr committed Feb 27, 2012
Showing with 97 additions and 118 deletions.
  1. +4 −4 Lab2/Lab2.c
  2. +2 −1 Lab2/Lab2.uvproj
  3. +33 −31 Lab2/os.c
  4. +2 −1 Startup.s
  5. +54 −76 adc.c
  6. +1 −4 adc.h
  7. +1 −1 uart.c
View
8 Lab2/Lab2.c
@@ -266,14 +266,14 @@ int main(void){
OS_Fifo_Init(8); // ***note*** 4 is not big enough*****
//*******attach background tasks***********
- //OS_AddButtonTask(&ButtonPush,2);
+ OS_AddButtonTask(&ButtonPush,2);
OS_AddPeriodicThread(&DAS,PERIOD,1); // 2 kHz real time sampling
NumCreated = 0 ;
// create initial foreground threads
- //NumCreated += OS_AddThread(&Interpreter,128,2);
- //NumCreated += OS_AddThread(&Consumer,128,1);
- //NumCreated += OS_AddThread(&PID,128,3);
+ NumCreated += OS_AddThread(&Interpreter,128,2);
+ NumCreated += OS_AddThread(&Consumer,128,1);
+ NumCreated += OS_AddThread(&PID,128,3);
OS_Launch(TIMESLICE); // doesn't return, interrupts enabled in here
return 0; // this never executes
View
3 Lab2/Lab2.uvproj
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_proj.xsd">
- <SchemaVersion>1.0</SchemaVersion>
+ <SchemaVersion>1.1</SchemaVersion>
<Header>### uVision Project, (C) Keil Software</Header>
@@ -29,6 +29,7 @@
<SLE66CMisc></SLE66CMisc>
<SLE66AMisc></SLE66AMisc>
<SLE66LinkerMisc></SLE66LinkerMisc>
+ <SFDFile></SFDFile>
<UseEnv>0</UseEnv>
<BinPath></BinPath>
<IncludePath></IncludePath>
View
64 Lab2/os.c
@@ -119,38 +119,40 @@ void OS_Init(void){
//Systick Init (Thread Scheduler)
//taken care of in OS_Launch
- // Imter Initis caglore!
- 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);
- TimerControlTrigger(TIMER0_BASE, TIMER_B, true);
- TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()/1000);
- TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
- TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT);
- IntEnable(INT_TIMER0A); // TIMELORD updater
- //IntEnable(INT_TIMER0B); // Not in use right now
-
- 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 Debugging LED
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
- GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);
- GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0);
+ // 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);
+
+ // 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,0);
+ OS_InitSemaphore(&oled_free,1);
OS_InitSemaphore(&OSMailBoxSema4,0);
OS_MailBox_Init();
@@ -161,7 +163,7 @@ void OS_Init(void){
//ADC
-// ADC_Init(1000); // Init ADC to run @ 1KHz
+ 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)
View
3 Startup.s
@@ -93,6 +93,7 @@ __heap_limit
EXTERN Timer1B_Handler
EXTERN Timer2A_Handler
EXTERN Timer2B_Handler
+ EXTERN ADCIntHandler
;******************************************************************************
;
; The vector table.
@@ -130,7 +131,7 @@ __Vectors
DCD IntDefaultHandler ; PWM Generator 1
DCD IntDefaultHandler ; PWM Generator 2
DCD IntDefaultHandler ; Quadrature Encoder
- DCD IntDefaultHandler ; ADC Sequence 0
+ DCD ADCIntHandler ; ADC Sequence 0
DCD IntDefaultHandler ; ADC Sequence 1
DCD IntDefaultHandler ; ADC Sequence 2
DCD IntDefaultHandler ; ADC Sequence 3
View
130 adc.c
@@ -24,41 +24,26 @@ Description: Helper functions for Timer-based ADC operation
#include "os.h"
unsigned long adc_last_value;
-unsigned int adc_samples;
unsigned char adc_status;
void (*function)(unsigned short);
-extern int TIMELORD;
-
// ADC Interrupt Handler
void ADCIntHandler(){
- // Clear Interrupt
- ADCIntClear(ADC0_BASE, 0);
// Update value
- ADCSequenceDataGet(ADC_BASE, 3, &adc_last_value);
+ ADCSequenceDataGet(ADC_BASE, 0, &adc_last_value);
// Call Periodic function
- function(adc_last_value);
-
- // Check to see if we're done
- if (--adc_samples == 0){
- // Disable ADC Interrupts
- ADCIntDisable(ADC0_BASE, 0);
-
- // Update status
- adc_status = ADC_IDLE;
- }
+ if (function != 0)
+ function(adc_last_value);
+
+ // Clear Interrupt
+ ADCIntClear(ADC0_BASE, 0);
}
// Initialize ADC w/ Timer0
-void ADC_Init(unsigned long freq){
- // Enable Peripheral
- SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC);
- IntEnable(INT_ADC0);
-
- // ADC Pins are dedicated.
- // No need to get GPIO Type
+void ADC_Init(){
+ // See OS_Init
// Set status
adc_status = ADC_IDLE;
@@ -67,78 +52,71 @@ void ADC_Init(unsigned long freq){
// Get status of ADC
unsigned short ADC_Status(){ return adc_status; }
-// Internally start ADC
-void ADC_Enable(unsigned int samples){
- // Set number of samples before finished
- adc_samples = samples;
-
- // Change status
- adc_status = ADC_BUSY;
-
- // Enable ADC Interrupts
- //ADCIntEnable(ADC0_BASE, 0);
- ADCProcessorTrigger(ADC0_BASE, 3);
-}
-
// Perform ADC on Channel
unsigned short ADC_Read(unsigned int channelNum){
// Make sure channelNum is value 0 to 3
ASSERT(channelNum < 4);
+ // Disable calling function
+ function = 0;
+
// Setup ADC Sequence
- ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
- ADCSequenceStepConfigure(ADC0_BASE, 0, channelNum, channelNum | ADC_CTL_IE | ADC_CTL_END);
+ ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
+ ADCSequenceStepConfigure(ADC0_BASE, 0, 0, channelNum | ADC_CTL_IE | ADC_CTL_END);
+ ADCSequenceEnable(ADC0_BASE, 0);
+ ADCIntEnable(ADC0_BASE, 0);
+ IntEnable(INT_ADC0);
// Start Conversion
- ADC_Enable(1);
+ ADCProcessorTrigger(ADC0_BASE, 0);
// Wait for ADC to finish
- while (adc_status != ADC_IDLE);
+ while (!ADCIntStatus(ADC_BASE, 0, false));
// Return value
return (short) adc_last_value;
}
// Collect multiple samples from single ADC Channel
void ADC_Collect(unsigned int channelNum, unsigned int freq, void (*func)(unsigned short), unsigned int samples){
- unsigned int i;
-
- // Check parameters
- ASSERT(channelNum < 4);
- ASSERT(freq >= 100);
- ASSERT(freq <= 10000);
-
- // Set channel to sample from
- ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
- ADCSequenceStepConfigure(ADC0_BASE, 0, channelNum, channelNum | ADC_CTL_IE | ADC_CTL_END);
-
- // Set Sample Frequency
- TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet() / freq);
-
- // Set function pointer
- function = func;
-
- // Start conversions
- ADC_Enable(samples);
-
- // Collect samples as they become availble
- adc_last_value = ADC_SAMPLE_NOT_READY;
- for(i=0; i<samples; i++){
- // Idle until sample is ready
- while(adc_last_value == ADC_SAMPLE_NOT_READY);
+ unsigned int i;
+
+ // Check parameters
+ ASSERT(channelNum < 4);
+ ASSERT(freq >= 100);
+ ASSERT(freq <= 10000);
+
+ // Set channel to sample from
+ ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0);
+ ADCSequenceStepConfigure(ADC0_BASE, 0, 0, channelNum | ADC_CTL_IE | ADC_CTL_END);
+ ADCSequenceEnable(ADC0_BASE, 0);
+ ADCIntEnable(ADC0_BASE, 0);
+
+ // Start Conversion
+ ADCProcessorTrigger(ADC0_BASE, 0);
- // Read new sample
- //buffer[i] = (unsigned short) adc_last_value;
+ // Setup hardware timer
+ TimerLoadSet(TIMER0_BASE, TIMER_B, SysCtlClockGet() / freq);
+ TimerEnable(TIMER0_BASE, TIMER_B);
+ IntEnable(INT_TIMER1A);
- // Reset adc_last_sample
+ // Set function pointer
+ function = func;
+
+ // Start conversions
adc_last_value = ADC_SAMPLE_NOT_READY;
+ IntEnable(INT_ADC0);
- /* Should not need this
- if (adc_status == ADC_IDLE)
- break;
- */
- }
-
- // Set status to finished
- adc_status = ADC_IDLE;
+ // Collect Data
+ for(i=0; i<samples; i++){
+ // Wait for ADC to finish
+ while (adc_last_value == ADC_SAMPLE_NOT_READY);
+
+ // Reset control variable
+ adc_last_value = ADC_SAMPLE_NOT_READY;
+ }
+
+ // Turn off interrupts
+ IntEnable(INT_TIMER1A);
+ IntEnable(INT_ADC0);
}
View
5 adc.h
@@ -19,14 +19,11 @@ Description: Helper functions for Timer-based ADC operation
void ADC0IntHandler(void);
// Initialize ADC w/ Timer0
-void ADC_Init(unsigned long freq);
+void ADC_Init(void);
// Get status of ADC
unsigned short ADC_Status(void);
-// Internally start ADC
-void ADC_Enable(unsigned int samples);
-
// Perform ADC on Channel
unsigned short ADC_Read(unsigned int channelNum);
View
2 uart.c
@@ -109,7 +109,7 @@ void UARTInit(){
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
- GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
+ GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |

0 comments on commit 9b47a69

Please sign in to comment.