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.

Stellaris LM3S3748 Evaluation Board

Other Parts Discussed in Thread: LM3S3748

Hi, everyone, fine?
I know that this forum is not about Stellaris, but the one which would help no longer exists. Thus, sorry for that.

  Could anyone please help me along with  a LM3S3748 program ?
I've been trying hard to get some samples using its ADC block and have failed in doing so. I'm just using one channel (CH5) to sample a small DC signal (less than 3 V). The program is supposed to get this signal (a 10-bit value from the FIFO) and compare it with a predetermined value to activate a blinky Led depending on whether the comparison is true or not. The program is very simple (just to test the channel) but it's not working.
I have the Evaluation Board powered up directly from the PC  by the USB debugger power input (with SW3 key in SELF position).

Could anyone point out the problem?

Thanks so much in advance.

That's the program:

#include "inc/lm3s3748.h"
#include "driverlib/adc.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "inc/hw_ints.h"
#include "driverlib/gpio.c"


 void int_handler(void); // Prototype of int_handler() function.

int main (void)
{

 //---------------------------------------------------------------------------------------//
 
 //---------------------------------------------------------------------------------------//
 //    Enables ADC clock and set the sample rate.
     SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
     SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
  // Initialize peripheral D - pin 6- to be an ADC analog input.
    GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_6);
 // Enable the fourth sample sequence to capture the value of channel 0 when
 // the processor trigger occurs.
      ADCSequenceDisable(ADC0_BASE, 3);
      ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_ALWAYS, 0);
      ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH5);
      ADCSequenceEnable(ADC0_BASE, 3);
 // Trigger the sample sequence.
 // ADCProcessorTrigger(ADC0_BASE, 1);
      ADCIntRegister(ADC0_BASE, 3, int_handler); //Register int_handler () for ADC0_BASE seq. 1 and ativates interruptions general key.
      ADCIntEnable(ADC0_BASE, 3);      //Activates interruption for the ADC0_BASE, sequence 1.
    IntEnable(INT_ADC0);

      for(;;){} // infinite loop. Just wait until the interrupt occurs.
//    while(1){} // infinite loop. Just wait until the interrupt occurs

  //    return (0);
}// End of funtion main().
                                                              
//-----------------------------------------------------------------------------------------------//


//Interruption treatment

void int_handler(void)
{

 volatile unsigned long ulLoop;
 unsigned long ulvalue = 0;
 unsigned long lSampleCount = 0;

    //
    // Enable the GPIO port that is used for the on-board LED.
    //
    SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF;

    //
    // Do a dummy read to insert a few cycles after enabling the peripheral.
    //
    ulLoop = SYSCTL_RCGC2_R;

    //
    // Enable the GPIO pin for the LED (PF0).  Set the direction as output, and
    // enable the GPIO pin for digital function.
    //
    GPIO_PORTF_DIR_R = 0x01;
    GPIO_PORTF_DEN_R = 0x01;    



    ADCIntClear(ADC0_BASE, 3);// Clear ADC interrupt register.

   // Wait a moment until Int buffer is clear
    for(ulLoop = 0; ulLoop < 200000; ulLoop++)
        {
        }
  // Get data from the FIFO
    ADCSequenceDataGet(ADC0_BASE, 3, &ulvalue);

    ulvalue = ulvalue & 0x000003FF;

    if (ulvalue<=0x00000100)
   {
 
     //
        // Turn on the LED.
        //
        GPIO_PORTF_DATA_R |= 0x01;

        //
        // Delay for a bit.
        //
        for(ulLoop = 0; ulLoop < 200000; ulLoop++)
        {
        }

        //
        // Turn off the LED.
        //
        GPIO_PORTF_DATA_R &= ~(0x01);

        //
        // Delay for a bit.
        //
        for(ulLoop = 0; ulLoop < 200000; ulLoop++)
        {
        }
     }
        
}

  • I don't know anything about stellaris, so this is generic suggestion: init gpio in main(), dont try to blink led in the isr, just switch it on if condition ok, switch off if not. It is unclear why delay needed after adcintclear, but note that it could be optimized by compiler to no delay at all.
  • Hello user454462654,

    The LM3S forum is now Read Only and you have posted on the correct forum.

    Though my expertise on LM3S device is limited but I think the Interrupt Enable function IntEnable must be passing INT_ADC0SS3 and not INT_ADC0

    Regards
    Amit
  • Hi, Ilmars, fine? thanks for responding.

    The int_handler() allows the Led to blink if the the statement (ulvalue<=0x00000100) is true, i. e., if the filtered 10-bit value acquired from the the FIFO by     ADCSequenceDataGet() is less than or equal to 0x00000100 (which matches to around 1Volt, from a range of 0V - 3V) the Led starts blinking. The " ulvalue = ulvalue & 0x000003FF; " is a filter to get the first 10 bits from the FIFO, which is 32 bit long.

    The delay is not needed right after ADCIntClear(), i put it there to guarantee the interrupt register is cleaned up, but it's not necessary.

    GPIO in main() is the right thing to do ( professional) and it works fine inside int_handler() too, at least for a test. The interruption part works very well (always triggered) and i've tested it using other statements/conditions without trying to get any sample. The problem lies in the "sample part". The blinking Led always starts by the same condition, as if the the peripheral is not reading the varying voltage that i apply at the input (channel CH5) and the FIFO never changes its value. I tried another input, but didn't work.

    PS: the comments in the code have some changed words/values.

    Again, Ilmars, thank you for your suggestion.

    Best regards.

  • Hi, Amit , fine? Thanks for your answer.
    It's good to know i can post it here, thank you.

    These lines below allow the sequence 3 interruption to work:

    ADCIntRegister(ADC0_BASE, 3, int_handler); //Register int_handler () for ADC0_BASE seq. 3 and ativates interruptions general key.
    ADCIntEnable(ADC0_BASE, 3); //Activates interruption for the sequence 3 of ADC0_BASE.
    IntEnable(INT_ADC0); //ativates ADC0 interruptions general key.

    I couldn't find the macro definition " INT_ADC0SS3 " in any library. Do you remember which one you could find it in ?

    Best regards,
    Roger
  • Hello user454462654,

    Which version of StellarisWare are you using?

    Regards
    Amit
  • My tech firm has past used (similar) LM3S devices - w/great success.

    We note that your failure was described (as so often occurs here) as, "Not working."    And that "not working" is so vague as to carry over to your guidance - provided here.

    Firm/I are strong believers in "KISS" - it appears you've "overly complicated" your problem-solving by the introduction of the, "Interrupt."   Your problem statement - in no way - suggests that the complication of any, "interrupt" is mandatory.

    You may eliminate the interrupt - and far faster/easier confim your ADC operation AND, "voltage level decision logic" -  via a simple program loop!   No interrupt required.

    You may devise the loop such that it regularly and repeatedly "reads the ADC's value" - then evaluates that value - and takes the appropriate action upon the results of that ADC value's evaluation.

    Later - as and if required - you may "extend" into interrupts.   But for now - with, "Not working" as your report - simplicity - NOT more complexity - is your best friend!

  • Hello user454462654,

    For the records, I have StellarisWare revision 10636 and the file hw_ints.h in inc directory has the following

    #define INT_ADC0SS3 33 // ADC0 Sequence 3

    Regards
    Amit
  • And also - for the record - StellarisWare ver. 9453 (one prior to 10636 referenced by Amit) is the last one to accept LM3S AND LX4F. (10636 "shies away" from LX4F - for unexplained reason)

    Such is of no consequence to this poster - yet may be critical to those w/LX4F devices and eval boards.

    There is an "ideal" (i.e. KISS approved) example (interrupt free - of course) which may be found under: StellarisWare\9453\examples\peripherals\adc\single_ended.c.   Serious cb1 coinage would be placed on poster's marker should that code be employed...

    We note that, "Loss of JTAG AND difficulties w/Interrupts" are two of the dominant problem areas for, "derailed" posters - here...   KISS teaches, "One small, simple problem at a time."    Pity such practice is not more universal...

  • Hello, Amit,

    Sorry for late replying. I'm still  undergraduate and had a couple of exams this week.

    The device i'm using is a 2009 Stellaris® LM3S3748 Evaluation Kit version. It's a pretty old version, but that's the only one i have in the lab to work with by now.



    Thanks a lot for your help.

    Best regards


    Roger

  • Hello Roger,

    What is the Software version for StellarisWare?

    Regards
    Amit
  • Hello Amit,
    The Software is uVision 3.
    I didn't find #define INT_ADC0SS3 33 // ADC0 Sequence 3 in file hw_ints.h
    but i found #define INT_ADC3 33 // ADC Sequence 3 , which i think is equivalent.
    I'll try it out.

    Regards
    Roger
  • Hello, cb1_mobile, fine?
    I understand your point and i've got into more details already. I used interruption because the program's gonna get more complex later. So i'm testing this structure now with a very simple task to make sure it'll work later with a complex one. The interruption part works fine. The problem is that i can't get one single sample in the FIFO as i inject small DC voltage signals, as if the the hardware cannot access the port, and i have enabled all the ports which the channels is located in, at least i guess so.

    Thanks a lot for your help, i really appreciate your suggestion.

    Best regards
    Roger