Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ADC shit. It works! (As fast as I can think of)

Signed-off-by: Cruz Monrreal II <Cruz.Monrreal@gmail.com>
  • Loading branch information...
commit 66a294f64997a985488dd333cd90f8d739fd5f0c 1 parent cf24377
@cmonr cmonr authored
Showing with 23 additions and 37 deletions.
  1. +1 −2  Lab2/os.c
  2. +2 −2 Startup.s
  3. +20 −30 adc.c
  4. +0 −3  adc.h
View
3  Lab2/os.c
@@ -145,6 +145,7 @@ void OS_Init(void){
// Init ADC Stuff
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
+ SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS);
// Init Debugging LED
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
@@ -161,11 +162,9 @@ void OS_Init(void){
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);
View
4 Startup.s
@@ -131,10 +131,10 @@ __Vectors
DCD IntDefaultHandler ; PWM Generator 1
DCD IntDefaultHandler ; PWM Generator 2
DCD IntDefaultHandler ; Quadrature Encoder
- DCD ADCIntHandler ; ADC Sequence 0
+ DCD IntDefaultHandler ; ADC Sequence 0
DCD IntDefaultHandler ; ADC Sequence 1
DCD IntDefaultHandler ; ADC Sequence 2
- DCD IntDefaultHandler ; ADC Sequence 3
+ DCD ADCIntHandler ; ADC Sequence 3
DCD IntDefaultHandler ; Watchdog
DCD Timer0A_Handler ; Timer 0A
DCD Timer0B_Handler ; Timer 0B
View
50 adc.c
@@ -25,19 +25,18 @@ Description: Helper functions for Timer-based ADC operation
static void (*function)(unsigned short);
unsigned long adc_last_value;
-unsigned char adc_status;
// ADC Interrupt Handler
void ADCIntHandler(){
// Update value
- ADCSequenceDataGet(ADC_BASE, 0, &adc_last_value);
-
+ ADCSequenceDataGet(ADC0_BASE, 3, &adc_last_value);
+
+ // Clear Interrupt
+ ADCIntClear(ADC0_BASE, 3);
+
// Call Periodic function
if (function != 0)
function(adc_last_value);
-
- // Clear Interrupt
- ADCIntClear(ADC0_BASE, 0);
}
// Initialize ADC w/ Timer0
@@ -49,9 +48,6 @@ void ADC_Init(){
function = 0;
}
-// Get status of ADC
-unsigned short ADC_Status(){ return adc_status; }
-
// Perform ADC on Channel
unsigned short ADC_Read(unsigned int channelNum){
// Make sure channelNum is value 0 to 3
@@ -62,20 +58,20 @@ unsigned short ADC_Read(unsigned int channelNum){
// Turn off interrupts
IntDisable(INT_TIMER0B);
- IntDisable(INT_ADC0);
+ IntDisable(INT_ADC3);
// Setup ADC Sequence
- 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);
+ ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
+ ADCSequenceStepConfigure(ADC0_BASE, 3, 0, channelNum | ADC_CTL_IE | ADC_CTL_END);
+ ADCSequenceEnable(ADC0_BASE, 3);
+ ADCIntEnable(ADC0_BASE, 3);
+ IntEnable(INT_ADC3);
// Start Conversion
- ADCProcessorTrigger(ADC0_BASE, 0);
+ ADCProcessorTrigger(ADC0_BASE, 3);
// Wait for ADC to finish
- while (!ADCIntStatus(ADC_BASE, 0, false));
+ while (!ADCIntStatus(ADC0_BASE, 3, false));
// Return value
return (short) adc_last_value;
@@ -90,23 +86,17 @@ void ADC_Collect(unsigned int channelNum, unsigned int freq, void (*func)(unsign
// Turn off interrupts
IntDisable(INT_TIMER0B);
- IntDisable(INT_ADC0);
-
- // Setup ADC Sequence
- 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);
+ IntDisable(INT_ADC3);
// Set function pointer
function = func;
- // Start conversions
- //adc_last_value = ADC_SAMPLE_NOT_READY;
- IntEnable(INT_ADC0);
+ // Setup ADC Sequence
+ ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
+ ADCSequenceStepConfigure(ADC0_BASE, 3, 0, channelNum | ADC_CTL_IE | ADC_CTL_END);
+ ADCSequenceEnable(ADC0_BASE, 3);
+ ADCIntEnable(ADC0_BASE, 3);
+ IntEnable(INT_ADC3);
// Setup hardware timer
TimerLoadSet(TIMER0_BASE, TIMER_B, SysCtlClockGet() / freq);
View
3  adc.h
@@ -21,9 +21,6 @@ void ADC0IntHandler(void);
// Initialize ADC w/ Timer0
void ADC_Init(void);
-// Get status of ADC
-unsigned short ADC_Status(void);
-
// Perform ADC on Channel
unsigned short ADC_Read(unsigned int channelNum);
Please sign in to comment.
Something went wrong with that request. Please try again.