This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Can somebody help me with reading a sensor on a stellaris launchpad?

Below is the code that I am using to initialize, read the sensor, and call the function.  Can somebody help me figure out why I am not getting any values from my sensor? 

#include "C:/StellarisWare/inc/hw_memmap.h"
#include "C:/StellarisWare/inc/hw_types.h"
#include "C:/StellarisWare/driverlib/debug.h"
#include "C:/StellarisWare/driverlib/sysctl.h"
#include "C:/StellarisWare/driverlib/adc.h"
#include "C:/StellarisWare/driverlib/gpio.h"
#include "C:/StellarisWare/driverlib/pin_map.h"

#ifdef DEBUG
void__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif


void initialize_sensor(){

SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);
SysCtlADCSpeedSet(SYSCTL_ADCSPEED_250KSPS);
ADCSequenceDisable(ADC0_BASE, 0);

ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);

ADCSequenceEnable(ADC0_BASE, 0);

}
int read_sensor_a() {
unsigned long value[4];
unsigned long new_value = 0;
int ad_value;

ADCIntClear(ADC0_BASE, 0);
ADCProcessorTrigger(ADC0_BASE, 0);
while(!ADCIntStatus(ADC0_BASE, 0, false))
{
ADCSequenceDataGet(ADC0_BASE, 0, value);
new_value = value[0] + value[1] + value[2] + value[3];
new_value = new_value/4;
ad_value = (int) new_value;
}

return ad_value;

}

int main(){
initialize_sensor();
for(;;){
int value = read_sensor_a();

}

}

Any help or suggestions would be greatly appreciated.

  • Hi Samuel,

    It looks to me like you have configured Sample Sequence 1, but then use Sample Sequence0:

    Samuel Hosig said:

    ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);

    ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);

    Please fix that and see what happens.

    Regards,

    Sue

  • I made that fix but I'm still getting the same results.  Just to clarify something, the VBUS pin supplies 5V, correct?  The sensor that I am using needs 5V to operate, and I thought i read that the VBUS pin supplied 5V but I could be wrong and if I am that might be why its not working.

    Thanks,

    Sam

  • Hi Sam,

    The Launchpad is powered by the 5V input from the PC through either the Stellaris ICDI or the USB Device connector on the board.  SW3 must be set appropriately for the selected power source.  Can you send me your schematics to review?

    Regards,

    Sue

  • I don't have schematics to send you, but I can tell you that I am plugged in to the debug interface with the SW3 switched to the debug side.  My sensor power is plugged into  the VBUS pin, 3.1, my GND from the sensor is plugged into the GND pin, 2.1, and my output from the sensor is plugged into pin PE5, 1.6.  I think that is how i configured it in code.  Right now there is no other circuit that I am interfacing with just the sensor.

  • That sounds right.  I noticed you are not enabling ADC interrupts:

    ADCIntEnable(ADC0_BASE, 0);
    IntEnable(INT_ADC0SS0);

    As a result, your IntStatus should never be triggered.

    You should probably also disable the Sample Sequence before you get the data (you could do this in the interrupt handler):

    ADCSequenceDisable(ADC0_BASE, 0); 

    What does your interrupt handler look like?  Did you add the handler to your vector table?

    Regards,

    Sue

  • My Interrupt handler looks very simple, it just disables the sample sequence like you suggest and then calls the read sensor function.  It looks like the following:

    void ADCIntHandler(){
    ADCSequenceDisable(ADC0_BASE, 0);
    read_sensor_a();
    }

    I added the following lines into the ADCConfigure:

    ADCIntEnable(ADC0_BASE, 0);
    IntEnable(ADCIntHandler);

    and my vector table looks like the following (just a piece):

    IntDefaultHandler, // I2C0 Master and Slave
    IntDefaultHandler, // PWM Fault
    IntDefaultHandler, // PWM Generator 0
    IntDefaultHandler, // PWM Generator 1
    IntDefaultHandler, // PWM Generator 2
    IntDefaultHandler, // Quadrature Encoder 0
    ADCIntHandler, // ADC Sequence 0
    IntDefaultHandler, // ADC Sequence 1
    IntDefaultHandler, // ADC Sequence 2
    IntDefaultHandler, // ADC Sequence 3
    IntDefaultHandler, // Watchdog timer
    IntDefaultHandler, // Timer 0 subtimer A
    IntDefaultHandler, // Timer 0 subtimer B
    IntDefaultHandler, // Timer 1 subtimer A
    IntDefaultHandler, // Timer 1 subtimer B
    IntDefaultHandler, // Timer 2 subtimer A
    IntDefaultHandler, // Timer 2 subtimer B
    IntDefaultHandler, // Analog Comparator 0
    IntDefaultHandler, // Analog Comparator 1
    IntDefaultHandler, // Analog Comparator 2
    IntDefaultHandler, // System Control (PLL, OSC, BO)
    IntDefaultHandler, // FLASH Control
    IntDefaultHandler, // GPIO Port F
    IntDefaultHandler, // GPIO Port G
    IntDefaultHandler, // GPIO Port H
    IntDefaultHandler, // UART2 Rx and Tx
    IntDefaultHandler, // SSI1 Rx and Tx
    IntDefaultHandler, // Timer 3 subtimer A
    IntDefaultHandler, // Timer 3 subtimer B
    IntDefaultHandler, // I2C1 Master and Slave
    IntDefaultHandler, // Quadrature Encoder 1
    IntDefaultHandler, // CAN0
    IntDefaultHandler, // CAN1
    IntDefaultHandler, // CAN2
    IntDefaultHandler, // Ethernet
    IntDefaultHandler, // Hibernate
    IntDefaultHandler, // USB0
    IntDefaultHandler, // PWM Generator 3
    IntDefaultHandler, // uDMA Software Transfer
    IntDefaultHandler, // uDMA Error
    IntDefaultHandler, // ADC1 Sequence 0
    IntDefaultHandler, // ADC1 Sequence 1
    IntDefaultHandler, // ADC1 Sequence 2
    IntDefaultHandler, // ADC1 Sequence 3

    I still haven't been getting differing results.  Do I need to have some sort of delay function called somewhere?  I had to do that for my MSP430 launchpad.

     

  • Hi Sam,

    When you say you are not getting any values, what exactly do you mean?  Are you reading 0s or what?

    Sue

  • Sorry I guess I should have explained this earlier. I am getting a value but it isn't changing regardless of how far I move an object from the IR sensor.  So everytime I run it my return value is always the same.  I tested the sensor on my MSP430 launchpad and it was picking up different values from that so I don't think the sensor is busted.

  • Sam,

    Please try this experiment.  Let's take the sensor out of the equation.  Please use a power supply to supply various voltages to the ADC input.  Record the voltages and the ADC readings and share your results with me.

    Thanks,

    Sue

  • Hi Sam,

    Here is another suggestion:

    When you are using the processor trigger, you should clear the interrupt after waiting for the conversion to be completed.  Like this:

     

    ADCProcessorTrigger(ADC0_BASE, SEQUENCER);

    while(!ADCIntStatus(ADC0_BASE, SEQUENCER, false))

            {

            }

     

    ADCIntClear(ADC0_BASE, SEQUENCER);

    ADCSequenceDataGet(ADC0_BASE, SEQUENCER, ulADC0_Value);

    And you should also probably enable the sequencer before you leave the interrupt handler.

    Regards,

    Sue

  • Hi, 

    I have tried to implement everything that you have said, and I am in process of finding an AC power supply for the testing that you suggested earlier.  I am still having the same issue of the value not updating.  However, I have found that my interrupt is never triggering.  Before I was just calling the read sensor function but I took that out in hopes that my interrupt would be triggered and it never was. Since much has changed I have included the relevant functions below.  The Vector table is the same as above.

    int read_sensor_a() {
    unsigned long value[4];
    unsigned long new_value = 0;
    int ad_value;


    ADCProcessorTrigger(ADC0_BASE, 0);
    while(!ADCIntStatus(ADC0_BASE, 0, false))
    {

    }
    ADCIntClear(ADC0_BASE, 0);
    ADCSequenceDataGet(ADC0_BASE, 0, value);
    new_value = value[0] + value[1] + value[2] + value[3];
    new_value = new_value/4;
    ad_value = (int) new_value;
    ADCSequenceEnable(ADC0_BASE, 0);
    return ad_value;
    }

    void ADCIntHandler(){
    ADCSequenceDisable(ADC0_BASE, 0);
    ADCValue = read_sensor_a();
    ADCSequenceEnable(ADC0_BASE, 0);
    }

    void initialize_sensor(){

    SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);
    SysCtlADCSpeedSet(SYSCTL_ADCSPEED_250KSPS);

    ADCSequenceDisable(ADC0_BASE, 0);

    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);

    ADCSequenceEnable(ADC0_BASE, 0);
    ADCIntEnable(ADC0_BASE, 0);
    IntEnable(ADC_INT_SS0);
    IntMasterEnable();
    }

    I will hopefully find a AC supply tomorrow and can run the experiment.

    Thanks,


    Sam

  • Hi Sam,

    It's hard to know what is going on without seeing your whole program, but here are some debug ideas to try: 1. Try using the ALWAYS trigger and see if you can get an interrupt in this case.  2. Step through the code and see what happens at each step.

    If you are not getting an interrupt, I would expect the values to not change as you keep reading them.

    Regards,

    Sue

  • Sam:

    I have mentioned a few times that I have posted an ADC program with interrupts. It runs on the EKS-LM3S811 -- but it should adapt easily...

    http://e2e.ti.com/support/microcontrollers/stellaris_arm_cortex-m3_microcontroller/f/473/t/212263.aspx

    I will bet that the value that the value never changes is most likely 0xFF -- or possibly 0x00 hex (max or min) -- but why are we guessing? If you really want help do make some effort to make the information complete... What are you reading?

    Create the minimum program that demonstrates the problem and post it.

  • Hi Dave, 

    Below is my whole program, the only thing that is currently implemented is the read_sensor_a(), initializesensor(), and the interrupt handler.

    -----------------------------------------------------------------------------------------------------------------------------

    main.c

    #include "/inc/hw_memmap.h"
    #include "/inc/hw_types.h"
    #include "/driverlib/debug.h"
    #include "/driverlib/sysctl.h"
    #include "/driverlib/adc.h"
    #include "/driverlib/gpio.h"
    #include "/driverlib/pin_map.h"

    #ifdef DEBUG
    void__error__(char *pcFilename, unsigned long ulLine)
    {
    }
    #endif


    int ADCValue = 0;

    void Delay_ms(unsigned int ms);


    int read_sensor_a() {
    unsigned long value[4];
    unsigned long new_value = 0;
    int ad_value;


    ADCProcessorTrigger(ADC0_BASE, 0);
    while(!ADCIntStatus(ADC0_BASE, 0, false))
    {

    }
    ADCIntClear(ADC0_BASE, 0);
    ADCSequenceDataGet(ADC0_BASE, 0, value);
    new_value = value[0] + value[1] + value[2] + value[3];
    new_value = new_value/4;
    ad_value = (int) new_value;
    ADCSequenceEnable(ADC0_BASE, 0);
    return ad_value;
    }

    void ADCIntHandler(){
    ADCSequenceDisable(ADC0_BASE, 0);
    ADCValue = read_sensor_a();
    ADCSequenceEnable(ADC0_BASE, 0);
    }

    void initialize_sensor(){

    SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);
    SysCtlADCSpeedSet(SYSCTL_ADCSPEED_250KSPS);

    ADCSequenceDisable(ADC0_BASE, 0);

    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);

    ADCSequenceEnable(ADC0_BASE, 0);
    ADCIntEnable(ADC0_BASE, 0);
    IntEnable(ADC_INT_SS0);
    IntMasterEnable();
    }
    int read_sensor_b() {

    return 1;
    }

    int determine_terrain(int sensorValue){

    return 1;
    }

    void actuate(){


    }

    /*void Delay_ms(unsigned int ms){
    while(ms--){
    __delay_cycles(1000);
    }
    }*/

    /*
    * Function to determine if the foot is off the ground or on the ground
    *
    * Returns:
    * 1 - Foot is on the ground
    * 0 - Foot is off the ground
    *
    */
    int onOffGround(int sensorVal){
    int upDownReturn;
    if(sensorVal > 300){
    upDownReturn = 1;
    }else{
    upDownReturn = 0;
    }
    return upDownReturn;
    }

    /*
    * POST Process
    */
    int POST(){
    int retVal = 0;
    return retVal;
    }


    int main(){
    int working = 0;
    working = POST();
    initialize_sensor();
    if(working == 0){
    for(;;){
    int terrainReturn = determine_terrain(ADCValue);
    if(terrainReturn == 0)
    actuate();
    }
    }else{
    return 0;
    }
    }

    -------------------------------------------------------------------------------------------------------

    startup_css.c

    //*****************************************************************************
    //
    // startup_ccs.c - Startup code for use with TI's Code Composer Studio.
    //
    // Copyright (c) 2012 Texas Instruments Incorporated. All rights reserved.
    // TI Information - Selective Disclosure
    //
    //*****************************************************************************

    //*****************************************************************************
    //
    // Forward declaration of the default fault handlers.
    //
    //*****************************************************************************
    void ResetISR(void);
    static void NmiSR(void);
    static void FaultISR(void);
    static void IntDefaultHandler(void);
    void ADCIntHandler(void);


    //*****************************************************************************
    //
    // External declaration for the reset handler that is to be called when the
    // processor is started
    //
    //*****************************************************************************
    extern void _c_int00(void);

    //*****************************************************************************
    //
    // Linker variable that marks the top of the stack.
    //
    //*****************************************************************************
    extern unsigned long __STACK_TOP;

    //*****************************************************************************
    //
    // The vector table. Note that the proper constructs must be placed on this to
    // ensure that it ends up at physical address 0x0000.0000 or at the start of
    // the program if located at a start address other than 0.
    //
    //*****************************************************************************
    #pragma DATA_SECTION(g_pfnVectors, ".intvecs")
    void (* const g_pfnVectors[])(void) =
    {
    (void (*)(void))((unsigned long)&__STACK_TOP),
    // The initial stack pointer
    ResetISR, // The reset handler
    NmiSR, // The NMI handler
    FaultISR, // The hard fault handler
    IntDefaultHandler, // The MPU fault handler
    IntDefaultHandler, // The bus fault handler
    IntDefaultHandler, // The usage fault handler
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    IntDefaultHandler, // SVCall handler
    IntDefaultHandler, // Debug monitor handler
    0, // Reserved
    IntDefaultHandler, // The PendSV handler
    IntDefaultHandler, // The SysTick handler
    IntDefaultHandler, // GPIO Port A
    IntDefaultHandler, // GPIO Port B
    IntDefaultHandler, // GPIO Port C
    IntDefaultHandler, // GPIO Port D
    IntDefaultHandler, // GPIO Port E
    IntDefaultHandler, // UART0 Rx and Tx
    IntDefaultHandler, // UART1 Rx and Tx
    IntDefaultHandler, // SSI0 Rx and Tx
    IntDefaultHandler, // I2C0 Master and Slave
    IntDefaultHandler, // PWM Fault
    IntDefaultHandler, // PWM Generator 0
    IntDefaultHandler, // PWM Generator 1
    IntDefaultHandler, // PWM Generator 2
    IntDefaultHandler, // Quadrature Encoder 0
    ADCIntHandler, // ADC Sequence 0
    IntDefaultHandler, // ADC Sequence 1
    IntDefaultHandler, // ADC Sequence 2
    IntDefaultHandler, // ADC Sequence 3
    IntDefaultHandler, // Watchdog timer
    IntDefaultHandler, // Timer 0 subtimer A
    IntDefaultHandler, // Timer 0 subtimer B
    IntDefaultHandler, // Timer 1 subtimer A
    IntDefaultHandler, // Timer 1 subtimer B
    IntDefaultHandler, // Timer 2 subtimer A
    IntDefaultHandler, // Timer 2 subtimer B
    IntDefaultHandler, // Analog Comparator 0
    IntDefaultHandler, // Analog Comparator 1
    IntDefaultHandler, // Analog Comparator 2
    IntDefaultHandler, // System Control (PLL, OSC, BO)
    IntDefaultHandler, // FLASH Control
    IntDefaultHandler, // GPIO Port F
    IntDefaultHandler, // GPIO Port G
    IntDefaultHandler, // GPIO Port H
    IntDefaultHandler, // UART2 Rx and Tx
    IntDefaultHandler, // SSI1 Rx and Tx
    IntDefaultHandler, // Timer 3 subtimer A
    IntDefaultHandler, // Timer 3 subtimer B
    IntDefaultHandler, // I2C1 Master and Slave
    IntDefaultHandler, // Quadrature Encoder 1
    IntDefaultHandler, // CAN0
    IntDefaultHandler, // CAN1
    IntDefaultHandler, // CAN2
    IntDefaultHandler, // Ethernet
    IntDefaultHandler, // Hibernate
    IntDefaultHandler, // USB0
    IntDefaultHandler, // PWM Generator 3
    IntDefaultHandler, // uDMA Software Transfer
    IntDefaultHandler, // uDMA Error
    IntDefaultHandler, // ADC1 Sequence 0
    IntDefaultHandler, // ADC1 Sequence 1
    IntDefaultHandler, // ADC1 Sequence 2
    IntDefaultHandler, // ADC1 Sequence 3
    IntDefaultHandler, // I2S0
    IntDefaultHandler, // External Bus Interface 0
    IntDefaultHandler, // GPIO Port J
    IntDefaultHandler, // GPIO Port K
    IntDefaultHandler, // GPIO Port L
    IntDefaultHandler, // SSI2 Rx and Tx
    IntDefaultHandler, // SSI3 Rx and Tx
    IntDefaultHandler, // UART3 Rx and Tx
    IntDefaultHandler, // UART4 Rx and Tx
    IntDefaultHandler, // UART5 Rx and Tx
    IntDefaultHandler, // UART6 Rx and Tx
    IntDefaultHandler, // UART7 Rx and Tx
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    IntDefaultHandler, // I2C2 Master and Slave
    IntDefaultHandler, // I2C3 Master and Slave
    IntDefaultHandler, // Timer 4 subtimer A
    IntDefaultHandler, // Timer 4 subtimer B
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    IntDefaultHandler, // Timer 5 subtimer A
    IntDefaultHandler, // Timer 5 subtimer B
    IntDefaultHandler, // Wide Timer 0 subtimer A
    IntDefaultHandler, // Wide Timer 0 subtimer B
    IntDefaultHandler, // Wide Timer 1 subtimer A
    IntDefaultHandler, // Wide Timer 1 subtimer B
    IntDefaultHandler, // Wide Timer 2 subtimer A
    IntDefaultHandler, // Wide Timer 2 subtimer B
    IntDefaultHandler, // Wide Timer 3 subtimer A
    IntDefaultHandler, // Wide Timer 3 subtimer B
    IntDefaultHandler, // Wide Timer 4 subtimer A
    IntDefaultHandler, // Wide Timer 4 subtimer B
    IntDefaultHandler, // Wide Timer 5 subtimer A
    IntDefaultHandler, // Wide Timer 5 subtimer B
    IntDefaultHandler, // FPU
    IntDefaultHandler, // PECI 0
    IntDefaultHandler, // LPC 0
    IntDefaultHandler, // I2C4 Master and Slave
    IntDefaultHandler, // I2C5 Master and Slave
    IntDefaultHandler, // GPIO Port M
    IntDefaultHandler, // GPIO Port N
    IntDefaultHandler, // Quadrature Encoder 2
    IntDefaultHandler, // Fan 0
    0, // Reserved
    IntDefaultHandler, // GPIO Port P (Summary or P0)
    IntDefaultHandler, // GPIO Port P1
    IntDefaultHandler, // GPIO Port P2
    IntDefaultHandler, // GPIO Port P3
    IntDefaultHandler, // GPIO Port P4
    IntDefaultHandler, // GPIO Port P5
    IntDefaultHandler, // GPIO Port P6
    IntDefaultHandler, // GPIO Port P7
    IntDefaultHandler, // GPIO Port Q (Summary or Q0)
    IntDefaultHandler, // GPIO Port Q1
    IntDefaultHandler, // GPIO Port Q2
    IntDefaultHandler, // GPIO Port Q3
    IntDefaultHandler, // GPIO Port Q4
    IntDefaultHandler, // GPIO Port Q5
    IntDefaultHandler, // GPIO Port Q6
    IntDefaultHandler, // GPIO Port Q7
    IntDefaultHandler, // GPIO Port R
    IntDefaultHandler, // GPIO Port S
    IntDefaultHandler, // PWM 1 Generator 0
    IntDefaultHandler, // PWM 1 Generator 1
    IntDefaultHandler, // PWM 1 Generator 2
    IntDefaultHandler, // PWM 1 Generator 3
    IntDefaultHandler // PWM 1 Fault
    };

    //*****************************************************************************
    //
    // This is the code that gets called when the processor first starts execution
    // following a reset event. Only the absolutely necessary set is performed,
    // after which the application supplied entry() routine is called. Any fancy
    // actions (such as making decisions based on the reset cause register, and
    // resetting the bits in that register) are left solely in the hands of the
    // application.
    //
    //*****************************************************************************
    void
    ResetISR(void)
    {
    //
    // Jump to the CCS C initialization routine. This will enable the
    // floating-point unit as well, so that does not need to be done here.
    //
    __asm(" .global _c_int00\n"
    " b.w _c_int00");
    }

    //*****************************************************************************
    //
    // This is the code that gets called when the processor receives a NMI. This
    // simply enters an infinite loop, preserving the system state for examination
    // by a debugger.
    //
    //*****************************************************************************
    static void
    NmiSR(void)
    {
    //
    // Enter an infinite loop.
    //
    while(1)
    {
    }
    }

    //*****************************************************************************
    //
    // This is the code that gets called when the processor receives a fault
    // interrupt. This simply enters an infinite loop, preserving the system state
    // for examination by a debugger.
    //
    //*****************************************************************************
    static void
    FaultISR(void)
    {
    //
    // Enter an infinite loop.
    //
    while(1)
    {
    }
    }

    //*****************************************************************************
    //
    // This is the code that gets called when the processor receives an unexpected
    // interrupt. This simply enters an infinite loop, preserving the system state
    // for examination by a debugger.
    //
    //*****************************************************************************
    static void
    IntDefaultHandler(void)
    {
    //
    // Go into an infinite loop.
    //
    while(1)
    {
    }
    }

  • Sam:

    I may get a chance to look at this in an hour or two.

    To confirm: This is a program for a LM4F120Xl Launchpad.

    You should always state this explicitly. Don't make anybody guess about anything or you drag out the process.

  • Yes, sorry, I didn't realize there might be other launchpad models out there.  It is for the LM4F120XL Launchpad.

    I appreciate any help you might be able to give me.

  • Well it looks like different code again.

    Questions:

    1: Do you pay attention to warning messages from the compiler?

    2) If you do see a message do you try to find the cause?

    3) Did you look at an example of how interrupts were declared in the startup file -- or did you just guess? (Answer: You guessed. -- Have another look)

    4) What do you know about ADC trigger mechanisms? Did you read the Driver Library manual?

    5) What do you think about timers? Are they hard to configure?

    I could just give you the answers, but that requires an up front payment of $16,431,252.43  -- Alternatively you can look at your program and think for about five minutes...

  • Sam:

    I converted my program that is in the sharing forum. It now runs on the LM4F120XL as well -- complete with a timer applied to the ADC so you can use the ADC_trigger_timer... (Big hint here...).

    Perhaps I can get my code cleaned up and posted tonight or tomorrow... That's the good news.

    However, the bad news is that I will post it as a C++ example (minor changes --  really) just to be sure you see the challenge. ;-)

    That means a few extra lines -- maybe three or four -- plus a change to the linker cmd file as well -- again a minor change.

  • Hi Dave,

    I took your advice and used a timer and am now sampling at a set interval.  I looked at your other example and I think I was able to convert that code to C.  I am now able to sample the ADC but, I am still getting the same value time after time even if I change distance from the sensor, (the sensor is an IR distance sensor).  I don't know that I am doing the reading properly from the sensor, but at least the interrupt is triggering now.  

    I'm going to either later tonight or tomorrow see if I am getting the correct power from the board to the sensor.  I have tried using the GPIOPinRead function, because I from what I am understanding of the documentation  to see if there was any value on the pin that I am using for the ADC input, but I am getting zero consistently on that pin.  So I don't think that I am getting anything from the sensor.

    I would still be interested in seeing your code that you developed for this, if you want to post it, but if not that is fine too.

    Sam

  • Hi, 

    I have clean up my code for you to look at if you wanted to have a look at it:

    -----------------------------------------------------------------------------------------------------

    main.c

    #include "/inc/hw_memmap.h"
    #include "/inc/hw_ints.h"
    #include "/inc/hw_types.h"
    #include "/driverlib/debug.h"
    #include "/driverlib/sysctl.h"
    #include "/driverlib/adc.h"
    #include "/driverlib/gpio.h"
    #include "/driverlib/pin_map.h"
    #include "/driverlib/interrupt.h"
    #include "/driverlib/timer.h"

    #ifdef DEBUG
    void__error__(char *pcFilename, unsigned long ulLine)
    {
    }
    #endif



    int ADCValue = 0;


    int read_sensor_a() {
    unsigned long value[4];
    unsigned long new_value = 0;
    int ad_value;


    ADCProcessorTrigger(ADC0_BASE, 0);
    while(!ADCIntStatus(ADC0_BASE, 0, false))
    {

    }
    ADCIntClear(ADC0_BASE, 0);
    ADCSequenceDataGet(ADC0_BASE, 0, value);
    new_value = value[0] + value[1] + value[2] + value[3];
    new_value = new_value/4;
    ad_value = (int) new_value;
    ad_value = GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_5);
    ADCSequenceEnable(ADC0_BASE, 0);
    return ad_value;
    }

    void interrupt ADCIntHandler(){
    ADCSequenceDisable(ADC0_BASE, 0);
    ADCValue = read_sensor_a();
    ADCSequenceEnable(ADC0_BASE, 0);
    }

    void initialize_sensor(){

    SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);
    SysCtlADCSpeedSet(SYSCTL_ADCSPEED_250KSPS);

    ADCSequenceDisable(ADC0_BASE, 0);

    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);

    ADCSequenceEnable(ADC0_BASE, 0);

    ADCIntClear(ADC0_BASE, 0);
    ADCIntEnable(ADC0_BASE, 0);
    IntEnable(INT_ADC0);
    IntMasterEnable();
    }

    void interrupt Timer0IntHandler(){
    TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    ADCSequenceConfigure(ADC_BASE,1,ADC_TRIGGER_PROCESSOR,0);
    ADCProcessorTrigger(ADC0_BASE,0);
    }

    int read_sensor_b() {

    return 1;
    }

    int determine_terrain(int sensorValue){

    return 1;
    }

    void actuate(){


    }


    return upDownReturn;
    }

    /*
    * POST Process
    */
    int POST(){
    int retVal = 0;
    return retVal;
    }


    int main(){
    int working = 0;
    unsigned long ulPeriod;
    //unsigned long ulFrequency = 600000000;
    working = POST();
    initialize_sensor();
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    TimerConfigure(TIMER0_BASE,TIMER_CFG_32_BIT_PER);
    ulPeriod = (SysCtlClockGet());
    TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod-1);
    IntEnable(INT_TIMER0A);
    TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    TimerEnable(TIMER0_BASE, TIMER_A);
    TimerControlTrigger(TIMER0_BASE,TIMER_A,true);

    if(1 ==1 ){

    }
    if(working == 0){
    for(;;){
    int terrainReturn = determine_terrain(ADCValue);
    if(terrainReturn == 0)
    actuate();
    }
    }else{
    return 0;
    }
    }

    ----------------------------------------------------------------------------

    startup_ccs.c

    //*****************************************************************************
    //
    // startup_ccs.c - Startup code for use with TI's Code Composer Studio.
    //
    // Copyright (c) 2012 Texas Instruments Incorporated. All rights reserved.
    // TI Information - Selective Disclosure
    //
    //*****************************************************************************

    //*****************************************************************************
    //
    // Forward declaration of the default fault handlers.
    //
    //*****************************************************************************
    void ResetISR(void);
    static void NmiSR(void);
    static void FaultISR(void);
    static void IntDefaultHandler(void);
    extern void interrupt ADCIntHandler(void);
    extern void interrupt Timer0IntHandler(void);


    //*****************************************************************************
    //
    // External declaration for the reset handler that is to be called when the
    // processor is started
    //
    //*****************************************************************************
    extern void _c_int00(void);
    extern void interrupt ADCIntHandler(void);
    extern void interrupt Timer0IntHandler(void);

    //*****************************************************************************
    //
    // Linker variable that marks the top of the stack.
    //
    //*****************************************************************************
    extern unsigned long __STACK_TOP;

    //*****************************************************************************
    //
    // The vector table. Note that the proper constructs must be placed on this to
    // ensure that it ends up at physical address 0x0000.0000 or at the start of
    // the program if located at a start address other than 0.
    //
    //*****************************************************************************
    #pragma DATA_SECTION(g_pfnVectors, ".intvecs")
    void (* const g_pfnVectors[])(void) =
    {
    (void (*)(void))((unsigned long)&__STACK_TOP),
    // The initial stack pointer
    ResetISR, // The reset handler
    NmiSR, // The NMI handler
    FaultISR, // The hard fault handler
    IntDefaultHandler, // The MPU fault handler
    IntDefaultHandler, // The bus fault handler
    IntDefaultHandler, // The usage fault handler
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    IntDefaultHandler, // SVCall handler
    IntDefaultHandler, // Debug monitor handler
    0, // Reserved
    IntDefaultHandler, // The PendSV handler
    IntDefaultHandler, // The SysTick handler
    IntDefaultHandler, // GPIO Port A
    IntDefaultHandler, // GPIO Port B
    IntDefaultHandler, // GPIO Port C
    IntDefaultHandler, // GPIO Port D
    IntDefaultHandler, // GPIO Port E
    IntDefaultHandler, // UART0 Rx and Tx
    IntDefaultHandler, // UART1 Rx and Tx
    IntDefaultHandler, // SSI0 Rx and Tx
    IntDefaultHandler, // I2C0 Master and Slave
    IntDefaultHandler, // PWM Fault
    IntDefaultHandler, // PWM Generator 0
    IntDefaultHandler, // PWM Generator 1
    IntDefaultHandler, // PWM Generator 2
    IntDefaultHandler, // Quadrature Encoder 0
    ADCIntHandler, // ADC Sequence 0
    ADCIntHandler, // ADC Sequence 1
    ADCIntHandler, // ADC Sequence 2
    ADCIntHandler, // ADC Sequence 3
    IntDefaultHandler, // Watchdog timer
    Timer0IntHandler, // Timer 0 subtimer A
    IntDefaultHandler, // Timer 0 subtimer B
    IntDefaultHandler, // Timer 1 subtimer A
    IntDefaultHandler, // Timer 1 subtimer B
    IntDefaultHandler, // Timer 2 subtimer A
    IntDefaultHandler, // Timer 2 subtimer B
    IntDefaultHandler, // Analog Comparator 0
    IntDefaultHandler, // Analog Comparator 1
    IntDefaultHandler, // Analog Comparator 2
    IntDefaultHandler, // System Control (PLL, OSC, BO)
    IntDefaultHandler, // FLASH Control
    IntDefaultHandler, // GPIO Port F
    IntDefaultHandler, // GPIO Port G
    IntDefaultHandler, // GPIO Port H
    IntDefaultHandler, // UART2 Rx and Tx
    IntDefaultHandler, // SSI1 Rx and Tx
    IntDefaultHandler, // Timer 3 subtimer A
    IntDefaultHandler, // Timer 3 subtimer B
    IntDefaultHandler, // I2C1 Master and Slave
    IntDefaultHandler, // Quadrature Encoder 1
    IntDefaultHandler, // CAN0
    IntDefaultHandler, // CAN1
    IntDefaultHandler, // CAN2
    IntDefaultHandler, // Ethernet
    IntDefaultHandler, // Hibernate
    IntDefaultHandler, // USB0
    IntDefaultHandler, // PWM Generator 3
    IntDefaultHandler, // uDMA Software Transfer
    IntDefaultHandler, // uDMA Error
    IntDefaultHandler, // ADC1 Sequence 0
    IntDefaultHandler, // ADC1 Sequence 1
    IntDefaultHandler, // ADC1 Sequence 2
    IntDefaultHandler, // ADC1 Sequence 3
    IntDefaultHandler, // I2S0
    IntDefaultHandler, // External Bus Interface 0
    IntDefaultHandler, // GPIO Port J
    IntDefaultHandler, // GPIO Port K
    IntDefaultHandler, // GPIO Port L
    IntDefaultHandler, // SSI2 Rx and Tx
    IntDefaultHandler, // SSI3 Rx and Tx
    IntDefaultHandler, // UART3 Rx and Tx
    IntDefaultHandler, // UART4 Rx and Tx
    IntDefaultHandler, // UART5 Rx and Tx
    IntDefaultHandler, // UART6 Rx and Tx
    IntDefaultHandler, // UART7 Rx and Tx
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    IntDefaultHandler, // I2C2 Master and Slave
    IntDefaultHandler, // I2C3 Master and Slave
    IntDefaultHandler, // Timer 4 subtimer A
    IntDefaultHandler, // Timer 4 subtimer B
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    0, // Reserved
    IntDefaultHandler, // Timer 5 subtimer A
    IntDefaultHandler, // Timer 5 subtimer B
    IntDefaultHandler, // Wide Timer 0 subtimer A
    IntDefaultHandler, // Wide Timer 0 subtimer B
    IntDefaultHandler, // Wide Timer 1 subtimer A
    IntDefaultHandler, // Wide Timer 1 subtimer B
    IntDefaultHandler, // Wide Timer 2 subtimer A
    IntDefaultHandler, // Wide Timer 2 subtimer B
    IntDefaultHandler, // Wide Timer 3 subtimer A
    IntDefaultHandler, // Wide Timer 3 subtimer B
    IntDefaultHandler, // Wide Timer 4 subtimer A
    IntDefaultHandler, // Wide Timer 4 subtimer B
    IntDefaultHandler, // Wide Timer 5 subtimer A
    IntDefaultHandler, // Wide Timer 5 subtimer B
    IntDefaultHandler, // FPU
    IntDefaultHandler, // PECI 0
    IntDefaultHandler, // LPC 0
    IntDefaultHandler, // I2C4 Master and Slave
    IntDefaultHandler, // I2C5 Master and Slave
    IntDefaultHandler, // GPIO Port M
    IntDefaultHandler, // GPIO Port N
    IntDefaultHandler, // Quadrature Encoder 2
    IntDefaultHandler, // Fan 0
    0, // Reserved
    IntDefaultHandler, // GPIO Port P (Summary or P0)
    IntDefaultHandler, // GPIO Port P1
    IntDefaultHandler, // GPIO Port P2
    IntDefaultHandler, // GPIO Port P3
    IntDefaultHandler, // GPIO Port P4
    IntDefaultHandler, // GPIO Port P5
    IntDefaultHandler, // GPIO Port P6
    IntDefaultHandler, // GPIO Port P7
    IntDefaultHandler, // GPIO Port Q (Summary or Q0)
    IntDefaultHandler, // GPIO Port Q1
    IntDefaultHandler, // GPIO Port Q2
    IntDefaultHandler, // GPIO Port Q3
    IntDefaultHandler, // GPIO Port Q4
    IntDefaultHandler, // GPIO Port Q5
    IntDefaultHandler, // GPIO Port Q6
    IntDefaultHandler, // GPIO Port Q7
    IntDefaultHandler, // GPIO Port R
    IntDefaultHandler, // GPIO Port S
    IntDefaultHandler, // PWM 1 Generator 0
    IntDefaultHandler, // PWM 1 Generator 1
    IntDefaultHandler, // PWM 1 Generator 2
    IntDefaultHandler, // PWM 1 Generator 3
    IntDefaultHandler // PWM 1 Fault
    };

    //*****************************************************************************
    //
    // This is the code that gets called when the processor first starts execution
    // following a reset event. Only the absolutely necessary set is performed,
    // after which the application supplied entry() routine is called. Any fancy
    // actions (such as making decisions based on the reset cause register, and
    // resetting the bits in that register) are left solely in the hands of the
    // application.
    //
    //*****************************************************************************
    void
    ResetISR(void)
    {
    //
    // Jump to the CCS C initialization routine. This will enable the
    // floating-point unit as well, so that does not need to be done here.
    //
    __asm(" .global _c_int00\n"
    " b.w _c_int00");
    }

    //*****************************************************************************
    //
    // This is the code that gets called when the processor receives a NMI. This
    // simply enters an infinite loop, preserving the system state for examination
    // by a debugger.
    //
    //*****************************************************************************
    static void
    NmiSR(void)
    {
    //
    // Enter an infinite loop.
    //
    while(1)
    {
    }
    }

    //*****************************************************************************
    //
    // This is the code that gets called when the processor receives a fault
    // interrupt. This simply enters an infinite loop, preserving the system state
    // for examination by a debugger.
    //
    //*****************************************************************************
    static void
    FaultISR(void)
    {
    //
    // Enter an infinite loop.
    //
    while(1)
    {
    }
    }

    //*****************************************************************************
    //
    // This is the code that gets called when the processor receives an unexpected
    // interrupt. This simply enters an infinite loop, preserving the system state
    // for examination by a debugger.
    //
    //*****************************************************************************
    static void
    IntDefaultHandler(void)
    {
    //
    // Go into an infinite loop.
    //
    while(1)
    {
    }
    }

  • So I don't know what is wrong with pin PE5, but when I moved the ADC input to pin PE3 everything started working.  I have posted my code below.  The startup_ccs.c file has not changed from before.

    ------------------------------------------------------

    main.c

    #include "/inc/hw_memmap.h"
    #include "/inc/hw_ints.h"
    #include "/inc/hw_types.h"
    #include "/driverlib/debug.h"
    #include "/driverlib/sysctl.h"
    #include "/driverlib/adc.h"
    #include "/driverlib/gpio.h"
    #include "/driverlib/pin_map.h"
    #include "/driverlib/interrupt.h"
    #include "/driverlib/timer.h"

    #ifdef DEBUG
    void__error__(char *pcFilename, unsigned long ulLine)
    {
    }
    #endif


    int ADCValue = 0;

    int read_sensor_a() {
    unsigned long value[4];
    unsigned long new_value = 0;
    int ad_value;


    ADCProcessorTrigger(ADC0_BASE, 0);
    while(!ADCIntStatus(ADC0_BASE, 0, false))
    {

    }

    ADCSequenceDataGet(ADC0_BASE, 0, value);
    new_value = value[0] + value[1] + value[2] + value[3];
    new_value = new_value/4;
    ad_value = (int) new_value;
    ADCIntClear(ADC0_BASE, 0);
    ADCSequenceEnable(ADC0_BASE, 0);
    return ad_value;
    }

    void interrupt ADCIntHandler(){
    ADCSequenceDisable(ADC0_BASE, 0);
    ADCValue = read_sensor_a();
    ADCSequenceEnable(ADC0_BASE, 0);
    }

    void initialize_sensor(){

    SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
    SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS);

    ADCSequenceDisable(ADC0_BASE, 0);

    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);

    ADCSequenceEnable(ADC0_BASE, 0);

    ADCIntClear(ADC0_BASE, 0);
    ADCIntEnable(ADC0_BASE, 0);
    IntEnable(INT_ADC0);
    IntMasterEnable();
    }

    void interrupt Timer0IntHandler(){
    TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    ADCSequenceConfigure(ADC0_BASE,0,ADC_TRIGGER_PROCESSOR,0);
    ADCProcessorTrigger(ADC0_BASE,0);
    }

    int read_sensor_b() {

    return 1;
    }

    int determine_terrain(int sensorValue){

    return 1;
    }

    void actuate(){


    }

    int footOnOffGround(int sensorValue){

    }

    /*
    * POST Process
    */
    int POST(){
    int retVal = 0;
    return retVal;
    }


    int main(){
    int working = 0;
    unsigned long ulPeriod;
    //unsigned long ulFrequency = 600000000;
    working = POST();
    initialize_sensor();
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    TimerConfigure(TIMER0_BASE,TIMER_CFG_32_BIT_PER);
    ulPeriod = (SysCtlClockGet());
    TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod-1);
    IntEnable(INT_TIMER0A);
    TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    TimerEnable(TIMER0_BASE, TIMER_A);
    TimerControlTrigger(TIMER0_BASE,TIMER_A,true);

    if(working == 0){
    for(;;){
    int terrainReturn = determine_terrain(ADCValue);
    if(terrainReturn == 0)
    actuate();
    }
    }else{
    return 0;
    }
    }

  • Hi Sam,

    In ADCSequenceStepConfigure, the ulConfig parameter specifies which channel to read from.  You use channel 0, 1, 2, and 3:

    Samuel Hosig said:

    ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);

    PE3 Is channel 0. PE5 is channel 8.  You should change all of these parameters to be ADC_CTL_CH8 (if using PE5) or ADC_CTL_CH0 (if using PE3).

    Regards,

    Sue

  • Hi Sam,

    I would like to add three more observations relating your program(s):

    a) in your non-working PE5 version :

    new_value = new_value/4;
    ad_value = (int) new_value;
    ad_value = GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_5);
    ADCSequenceEnable(ADC0_BASE, 0);

    the line highlighted has no sense here - and this line magically disappeared in your working PE3 version; the cast is not needed on the second line. 

    b) In ADCIntHandler: first you disable the Sequencer_0 and then you try to read a value with your function read_sensor_a(), in which you call ADCProcessorTrigger(.. Sequencer_0 ). How this will work if the sequencer is disabled? Don't trigger it here anymore, once in the timer is enough. 

    c) In Timer0IntHandler: you don't need to call ADCSequenceConfigure(), once in an init routine is enough. 

    And here you can trigger the ADC. The conversion(s) will be finished in short time, generating the ADC interrupt; in ADC interrupt you don't need to re-start a new conversion and wait for completion - the results are ready to be picked up. 

    Petrei

  • Hi,

    Thanks for your help.

    A) that was a debugging line that I used to find that nothing was coming in on that pin.

    B)I didn't think I needed to do it again but in the example from the workbook it was triggered there, so I had that line in there, I will take it out.

    C) Ok, I will take that out too. 

    I have been able to get my board working with the sensor, and I have been able to add a second sensor on the board as well to use ADC1 so thank you to everybody who has helped.