|
|
morancf
Junior Boarder |
|
2007/01/09 05:40 |
|
Reading EV-LM38S11 Pot
Sorry for the lame question, but can someone share a code fragment (preferably for RealView) showing how to read the onboard Pot?
Thanks
login or register to reply
|
|
|
Capper
Expert Boarder |
|
2007/01/09 07:42 |
|
Re:Reading EV-LM38S11 Pot
Your best reference is probably the code in qs_ev-lm3s811.c, since the game demo uses the pot.
Several things need to be done to read the pot since it's tied to one of the analog inputs.
1) Turn on the analog inputs and configure the port pins.
2) Configure the ADC and a timer to sample the port.
3) Set up interrupt routines for the port and the timer and set the interrupt vectors to point to them.
4) Enable the interrupts.
Capper
login or register to reply
|
|
|
morancf
Junior Boarder |
|
2007/01/10 05:28 |
|
Re:Reading EV-LM38S11 Pot
I'm doing something very wrong here...
I cut the code out of the qs application as follows, but it just hangs at OSRAMInit(). The debugger just goes dead as well:
// // Readpot.c // // Read and display the Pot value via ADC0 //
#include "hw_types.h" #include "hw_ints.h" #include "hw_memmap.h" #include "interrupt.h" #include "debug.h" #include "sysctl.h" #include "diag.h" #include "adc.h" #include "gpio.h" #include "timer.h" #include "osram96x16.h"
#include <stdio.h>
#include "readpot.h"
//***************************************************************************** // // The error routine that is called if the driver library encounters an error. // //***************************************************************************** #ifdef DEBUG void __error__(char *pcFilename, unsigned long ulLine) { } #endif
//***************************************************************************** // // The interrupt handler for the ADC interrupt. // //***************************************************************************** void ADCIntHandler(void) { unsigned long ulData;
// // Clear the ADC interrupt. // ADCIntClear(ADC_BASE, 0);
// // Read the data from the ADC. // ADCSequenceDataGet(ADC_BASE, 0, &ulData);
// // Indicate that a timer interrupt has occurred. // HWREGBITW(&g_ulFlags, FLAG_CLOCK_TICK) = 1; }
int main(void) { char szBuffer[8];
// // Set the clocking to run directly from the crystal. // SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ);
// // Enable the peripherals used by the application. // SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC); //SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
// // Configure the ADC to sample the potentiometer when the timer expires. // After sampling, the ADC will interrupt the processor; this is used as // the heartbeat for the game. // ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_TIMER, 0); ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceEnable(ADC_BASE, 0); ADCIntEnable(ADC_BASE, 0); IntEnable(INT_ADC0); // // Configure the second timer to generate triggers to the ADC to sample the // potentiometer. // TimerConfigure(TIMER1_BASE, TIMER_CFG_32_BIT_PER); TimerLoadSet(TIMER1_BASE, TIMER_A, SysCtlClockGet() / 120); TimerControlStall(TIMER1_BASE, TIMER_A, true); TimerControlTrigger(TIMER1_BASE, TIMER_A, true); TimerEnable(TIMER1_BASE, TIMER_A); // // Initialize the OSRAM OLED display. // OSRAMInit(false);
while(1) { // // Wait until an update has been requested. // while(HWREGBITW(&g_ulFlags, FLAG_UPDATE) == 0) { }
sprintf(szBuffer, "Pot: %d", g_ulWheel); OSRAMClear(); OSRAMStringDraw(szBuffer, 0, 0);
// // Clear the update request flag. // HWREGBITW(&g_ulFlags, FLAG_UPDATE) = 0; }
DiagExit(0); }
login or register to reply
|
|
|
orinem
Expert Boarder |
|
2007/01/10 13:00 |
|
Re:Reading EV-LM38S11 Pot
Well, the first thing I see is you set FLAG_CLOCK_TICK in your interrupt handler, but test FLAG_UPDATE in main().
Secondly, szBuffer isn't big enough - it needs to be at least 10 chars to display 0..1023 - but I'd give it enough chars to display the full range of an unsigned long plus 6 for "Pot: ".
Orin.
login or register to reply
|
|
|
morancf
Junior Boarder |
|
2007/01/12 06:27 |
|
Re:Reading EV-LM38S11 Pot
OK, I fixed it. The main problem was I had the wrong "Startup.s" installed. The one in the qs example defines ADCInt, but mine didn't...
(Ugly) Working code attached for anyone else's use :)
// // Readpot.c // // Read and display the Pot value via ADC0 //
#include "hw_types.h" #include "hw_ints.h" #include "hw_memmap.h" #include "interrupt.h" #include "debug.h" #include "sysctl.h" #include "diag.h" #include "adc.h" #include "gpio.h" #include "timer.h" #include "osram96x16.h"
#include <stdio.h>
#include "readpot.h"
//***************************************************************************** // // The error routine that is called if the driver library encounters an error. // //***************************************************************************** #ifdef DEBUG void __error__(char *pcFilename, unsigned long ulLine) { } #endif
//***************************************************************************** // // The interrupt handler for the ADC interrupt. // //***************************************************************************** void ADCIntHandler(void) { unsigned long ulData;
// // Clear the ADC interrupt. // ADCIntClear(ADC_BASE, 0);
// // Read the data from the ADC. // ADCSequenceDataGet(ADC_BASE, 0, &ulData); g_ulWheel = ((g_ulWheel * 58982) + (ulData * 6554)) / 65536;
// // Increment the clock count. // HWREGBITW(&g_ulFlags, FLAG_CLOCK_COUNT_LOW) ^= 1; if(!HWREGBITW(&g_ulFlags, FLAG_CLOCK_COUNT_LOW)) { HWREGBITW(&g_ulFlags, FLAG_CLOCK_COUNT_HIGH) ^= 1; }
// // If the clock count has wrapped around to zero, then set a flag to // indicate that the display needs to be updated. // if((HWREGBITW(&g_ulFlags, FLAG_CLOCK_COUNT_LOW) == 0) && (HWREGBITW(&g_ulFlags, FLAG_CLOCK_COUNT_HIGH) == 0)) { HWREGBITW(&g_ulFlags, FLAG_UPDATE) = 1; }
// // Indicate that a timer interrupt has occurred. // HWREGBITW(&g_ulFlags, FLAG_CLOCK_TICK) = 1;
}
int main(void) { char szBuffer[16];
// // Set the clocking to run directly from the crystal. // SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ);
// // Enable the peripherals used by the application. // SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
// // Configure the ADC to sample the potentiometer when the timer expires. // After sampling, the ADC will interrupt the processor; this is used as // the heartbeat for the game. // ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_TIMER, 0); ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceEnable(ADC_BASE, 0); ADCIntEnable(ADC_BASE, 0); IntEnable(INT_ADC0); // // Configure the second timer to generate triggers to the ADC to sample the // potentiometer. // TimerConfigure(TIMER1_BASE, TIMER_CFG_32_BIT_PER); TimerLoadSet(TIMER1_BASE, TIMER_A, SysCtlClockGet() / 120); TimerControlStall(TIMER1_BASE, TIMER_A, true); TimerControlTrigger(TIMER1_BASE, TIMER_A, true); TimerEnable(TIMER1_BASE, TIMER_A); // // Initialize the OSRAM OLED display. // OSRAMInit(false);
while(1) { // // Wait until an update has been requested. // while(HWREGBITW(&g_ulFlags, FLAG_UPDATE) == 0) { }
sprintf(szBuffer, "Pot: %d", g_ulWheel); OSRAMClear(); OSRAMStringDraw(szBuffer, 0, 0);
// // Clear the update request flag. // HWREGBITW(&g_ulFlags, FLAG_UPDATE) = 0; }
DiagExit(0); }
login or register to reply
|
|