Jump to content

ADC Output

Recommended Posts



I recently found a ADC code in the forums. I plan to input it with a signal, but I dont know where to test the output.


Here's the code, credits to the maker.


#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"

main(void) {

uint32_t pui32ADC0Value[1];

SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN| SYSCTL_XTAL_16MHZ); //Set clock at 40 Mhz , Sometimes //ADC may not work at 80Mhz
ADCReferenceSet(ADC0_BASE, ADC_REF_INT); //Set reference to the internal reference
// You can set it to 1V or 3 V

ADCSequenceDisable(ADC0_BASE, 3); //It is always a good practice to disable ADC prior //to usage ,else the ADC may not be accurate // due to previous initializations
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); //Use the 3rd Sample sequencer

ADCSequenceStepConfigure(ADC0_BASE, 3, 0,ADC_CTL_CH8 | ADC_CTL_IE | ADC_CTL_END);
//Configure ADC to read from channel 8 ,trigger the interrupt to end data capture //

ADCSequenceEnable(ADC0_BASE, 3); //Enable the ADC
ADCIntClear(ADC0_BASE, 3); //Clear interrupt to proceed to data capture

while (1) {
ADCProcessorTrigger(ADC0_BASE, 3); //Ask processor to trigger ADC
while (!ADCIntStatus(ADC0_BASE, 3, false))
{ //Do nothing until interrupt is triggered

ADCIntClear(ADC0_BASE, 3); //Clear Interrupt to proceed to next data capture
ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value); //pui32ADC0Value is the value read

SysCtlDelay(SysCtlClockGet() / 12);
} //Suitable delay



Share this post

Link to post
Share on other sites


Could you clarify the question?

Is the question about how to access the result of the ADC conversion, or

looking for ideas on how to display the result in a test application, or

something else.

Share this post

Link to post
Share on other sites

Yes. How to access the result AND how to display it. Actually, I had an idea of using MatLab to display the output by using the FFT function on MatLab for the result of the ADC, however, I have no idea how to.

Share this post

Link to post
Share on other sites

For display, I would start by just printf the data.

It will come in on the USB CDC device, so can read in in the output window in CCS, or with a terminal.

Been decades since I used MatLab (it was on a VAX), so can't help you much with how to get the data into that.


As to how to access the result - look up the functions in the Stellarisware documentation,

particularly the description of ADCSequenceDataGet - i.e., the value is at the target of pui32ADC0Value


Depending on what you want to do with it, you could also try eLua - makes accessing the ADC for simple tasks a lot simpler.

I think Energia also simplifies doing simple things with ADC.

[Disclaimer - I did the port of Elua to the Stellaris launchpad http://forum.stellarisiti.com/topic/552-elua-for-stellaris-launchpad , but I have not used Energia.]

Of course that means using a different language or different environment.  But could be handy for testing/getting feet wet.  All depends what you want to do.


For example to read the ADC and print it on the terminal in eLua (after a little setup).  Full example is in the sample code.

adc.sample(chanel,128) -- start sampling

tsample = adc.getsample(chanel)  -- read result

term.print(1,3,string.format("ADC%02d: %04d\n", chanel, tsample)) -- print result (in this case at particular location on terminal screen)

Share this post

Link to post
Share on other sites

If you are asking how to send the value by UART - the Stellarisware examples use UART for console output.

Usually it is UART0 (which is connected to the programming part of the launchpad), but if want to use another UART should be able to adapt code.

(See uartstdio.c, .h in utils)


If question is getting MATLAB to read serial port - might want to check in MATLAB support fora.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now