nesslersreagent 0 Posted December 23, 2013 Share Posted December 23, 2013 Hi, I've recently upgraded my Energia IDE to the latest release 0101E0011. I'm using the Stellaris Launchpad with lm4f120h5qr.My sample ADC code doesn't seem to work right. Worked well in the previous release of Energia. The code compiles properly but does not produce the right output. The only changes made were to change "ADC_BASE" to "ADC0_BASE" as required. I've added Serial output code for debugging purposes. The serial output produced is: 1 2 3 Code: #include "Energia.h" #include "driverlib/sysctl.h" #include "driverlib/adc.h" void setup() { Serial.begin(115200); Serial.println("1"); //enable the adc0 peripherial. SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); Serial.println("2"); //set the speed to 1msps. SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS); Serial.println("3"); //set the auto avergage to 64. ADCHardwareOversampleConfigure(ADC0_BASE, 64); Serial.println("4"); //before setting up I must disable the sequence 3. ADCSequenceDisable(ADC0_BASE, 3); Serial.println("5"); //set the sequence to use (adc0 sequence 3). ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); Serial.println("6"); //set up the sequence step. //set up the last step and start an interrupt when the conversion it's over. ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END); Serial.println("7"); //enable the sequence again! ADCSequenceEnable(ADC0_BASE, 3); Serial.println("8"); } void loop() { } Quote Link to post Share on other sites
energia 485 Posted December 26, 2013 Share Posted December 26, 2013 I don't have access to hardware right now but as soon as I do I will give this a try. Just for kicks, what happens if you stick the code into the loop() and do a while(1) at the end? Quote Link to post Share on other sites
Lyon 3 Posted December 26, 2013 Share Posted December 26, 2013 Hi, Two problems with your code: 1) First, you should have a GPIO peripheral enabled and a specific pin configured as analog input pin. 2) In this function call ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END); the pin selected for conversion is still the internal temperature sensor (ADC_CTL_TS) - replace it with your analog pin declared above. Also, you don't need to declare ADC_CTL_IE if you do not use ADC interrupts. L energia and nesslersreagent 2 Quote Link to post Share on other sites
nesslersreagent 0 Posted December 27, 2013 Author Share Posted December 27, 2013 Hi, I have modified the code as per Lyon's suggestions and it works! Thanks. Also I've realised that the ADC speed must be changed before the ADC peripheral is enabled. This was the prime cause of all my troubles. Output: 1 2 3 4 5 6 7 8 Code: #include "Energia.h" #include "driverlib/sysctl.h" #include "driverlib/adc.h" void setup() { Serial.begin(115200); Serial.println("1"); //set the speed to 1Msps. SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS); //enable the adc0 peripherial. Serial.println("2"); SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); Serial.println("3"); //set the auto avergage to 64. ADCHardwareOversampleConfigure(ADC0_BASE, 64); Serial.println("4"); //before setting up I must disable the sequence 3. ADCSequenceDisable(ADC0_BASE, 3); Serial.println("5"); //set the sequence to use (adc0 sequence 3). ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); Serial.println("6"); //set up the sequence step. //set up the last step and start an interrupt when the conversion it's over. ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_END); Serial.println("7"); //enable the sequence again! ADCSequenceEnable(ADC0_BASE, 3); Serial.println("8"); } void loop() { } Quote Link to post Share on other sites
Lyon 3 Posted December 28, 2013 Share Posted December 28, 2013 Hi, You need to know also this: http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/293858.aspx Also, if Adc speed needed is 1M, then this is default at startup and can be omitted from setings. L energia 1 Quote Link to post Share on other sites
energia 485 Posted December 29, 2013 Share Posted December 29, 2013 Thanks @@Lyon for solving this one! Quote Link to post Share on other sites
nesslersreagent 0 Posted December 29, 2013 Author Share Posted December 29, 2013 Thanks Lyon for your help. Most helpful. Quote Link to post Share on other sites
rnightbane 0 Posted February 19, 2014 Share Posted February 19, 2014 Hi! How do you access the result of the ADC? Given that you put an input analog signal on the GPIO pin... Quote Link to post Share on other sites
energia 485 Posted February 20, 2014 Share Posted February 20, 2014 uint16_t value[1]; ROM_ADCSequenceDataGet(ADC0_BASE, 3, (unsigned long*) value) Also see wiring_analog.c for examples. If you do not need special sequencing, etc then use the build in analogRead(). Robert Quote Link to post Share on other sites
rnightbane 0 Posted February 28, 2014 Share Posted February 28, 2014 #include "Energia.h" #include "driverlib/sysctl.h" #include "driverlib/adc.h" #define A3 PE_0 void setup() { Serial.begin(512000); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS); SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0); ADCHardwareOversampleConfigure(ADC0_BASE, 64); ADCSequenceDisable(ADC0_BASE, 3); ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 3); } void loop() { int f; ADCProcessorTrigger(ADC0_BASE, 3); f = analogRead(A3); Serial.write(f); } thanks for answering my question... i modified a bit of his code, and placed analogRead() in place of AnalogSequenceGet(), so is my pin for analogRead() right? Since I assumed that PE_0 is the ADC pin used... Quote Link to post Share on other sites
energia 485 Posted February 28, 2014 Share Posted February 28, 2014 You do not need to setup the ADC when using analogRead(). The Sketch below should do what you are looking for. PE_0 is indeed ADC channel 3 as per the pin map posted here: http://energia.nu/Guide_StellarisLaunchPad.html #include "Energia.h" void setup() { Serial.begin(512000); } void loop() { int f; f = analogRead(A3); Serial.write(f); } Quote Link to post Share on other sites
rnightbane 0 Posted February 28, 2014 Share Posted February 28, 2014 I see, but what if I want to change the ADC speed, how do I change it if analogRead() already has its ADC set up as it is? And how many bits does the ADC transfer to UART? Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.