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.

how to take input(ECHO signal ,high) from a sensor in LM4F120H5QR using GPIO

first, I am a new user of LM4F120H5QR....I have very less knowledge about it....

I am using the sensor name "Ultrasonic range finder"....I have to give it the Trigger pulse of duration 10us and as response it gives me ECHO signal in form of "continuous high pulse".....

I want to take the input(ECHO) from my Ultra sonic range finder and give it to GPIO pin and want to measure the ON period of that Echo signal....

how to take input at a GPIO Pin??? and how can I measure the HIGH Pulse duration.....???

Please help...

thanx in advance....

  • Yours is beyond average, "early post." 

    That said - is there not conflict between, "continuous high pulse" (continuous and pulse) and your later desire to "measure high pulse duration?"  Clearly - "continuous" is not in play here...

    Surely we can provide model code - but these are very complex MCUs - and require a detailed, proper Set-Up and Configuration - to make even "perfect code" perform to expectations.

    Thus - we fail if we provide what you sought - and open Pandora's box of "on-going" explanation unless we provide exacting detail.

    Your description as, "new user to LX4F" - and lack of specific, related knowledge - offers little insight into your general programming and electronics capability.  Minus that detail - appropriate answer may be less than forthcoming...

  • Sir, I am sorry for confusing you.....with continuous i mean that it gives the high pulse for some duration.... I have less knowledge about LM4F...ya I can connect my sensor with my MCU....but problem is with programming......If u provide me code for this....that is very very helpful....

    thank you, sir

  • Preyash Vashi said:
    ......If u provide me code for this....that is very very helpful....

    One suspects that even with such provided code - you must perform multiple, other operations to create a meaningful system/sub-system. 

    My belief is that best help results from your serious read/review of MCU data manual, SW-DRL-UGxxxx, and the numerous code examples bound throughout StellarisWare.  Evidence is scant that you've made this very basic effort - and as stated earlier - this MCU is highly complex - demands that you get many things right and in the correct sequence.

    I'd be reluctant to order a meal - even from "world-class" restaurant - knowing that the chef had "cook-book" only solution - and little appreciation or recognition of the many necessary steps/processes involved.  (this - even if "chef" would find this (very helpful.")

  • sorry sir for responding too late....

    here....trigger is the PWM signal given to the my URF....

    I want take the ECHO in my MCU...and count its period......

    for that i have written code below.....

    #define PART_LM4F120H5QR true

    #include "inc/hw_ints.h"
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/sysctl.c"
    #include "driverlib/gpio.c"
    #include "driverlib/timer.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/interrupt.c"
    #include "driverlib/cpu.c"
    #include "driverlib/rom.h"

    void Inturf()
    {
              ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
                                   ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,0x02);
                                   //SysCtlDelay(200000);
                                ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,0x00);
    }
    unsigned long int ulPeriod, dutyCycle;
    long val;
    int main(void)
    {

        ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
        //ROM_IntEnable(INT_GPIOE);
        // 80 MHz system clock


        ulPeriod = 5200000;    //GENERATE 65mS DELAY WITH 10uS ON PERIOD
        dutyCycle = 5199200;

        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
        ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);

        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0);
        // Configure PC4 as WT0CCP0
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

        ROM_GPIOPinConfigure(GPIO_PC4_WT0CCP0);
        ROM_GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_4);








         //  val=ROM_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_7);          //read the data from pin7


        // Configure timer

        ROM_TimerConfigure(WTIMER0_BASE,  TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM);
        ROM_TimerLoadSet(WTIMER0_BASE, TIMER_A, ulPeriod);
        ROM_TimerMatchSet(WTIMER0_BASE, TIMER_A, dutyCycle); // PWM
        ROM_TimerEnable(WTIMER0_BASE, TIMER_A);

        GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_4);      //set PE4 as input pin
       /* GPIOPortIntRegister(GPIO_PORTE_BASE, Inturf);
            GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_4, GPIO_RISING_EDGE);
            GPIOPinIntEnable(GPIO_PORTE_BASE, GPIO_PIN_4);*/

            // read data

                 // if (val==0xF0);
    while(1)
    {
        val=GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_4);
        while(val==0)
        {

        }
        ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,0x02);
        //ROM_TimerConfigure(WTIMER1_BASE,  TIMER_CFG_SPLIT_PAIR);
          //  ROM_TimerLoadSet(WTIMER1_BASE, TIMER_A, ulPeriod);

        //timer enable
        while(val==0x10)
        {

        }
        //timer disable
        ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,0x00);
    }



    }

    hare i have tried polling method as well as intrerupt....

    Is what i am doing is right???If not....Please correct me....and give me the solution......

    i atteched the datasheet of my sensor.....I want connect it with my MCU....for object avoidance purpose,,,,

    thanx ...

  • Good for you - imho you've now demonstrated significant interest/effort - usually routes superior assistance - your doorstep.

    Have you compiled this code - w/out error?  Have you yet run it?  (and results of each were...?)

    As time/energy frees - will examine & suggest - questions above will speed/ease this process...  (btw - Sir reserved for my/other's "Dad" - many whom have "left the building")

    Update: Quickly scanned your code - note that you've got 3 Ports enabled - would it be simpler to confine to 1 or 2?  (understand that board edge-connector population may dictate - but 3 Ports seems bit much)

    Suggest this as a "quick/dirty" method - Sensor Free at this early stage - to build your familiarity/understanding.

    a) if possible - from one enabled Port - choose 2 "Split" Timer pins - and additional Port pin as output.  Set-up/configure all of them.

    b) Use of 2 Timers ("A" and "B") provides a simplification for your software - configure one to interrupt on external signal (your Sensor) rising edge - the 2nd Timer to interrupt on that same signal's falling edge.  (i.e. the Sensor signal is routed to 2 MCU Timer pins - which are connected together)

    c) In the beginning - I'd avoid the complications/burdens of your sensor - instead route a GPIO pin config'ed as output - into the 2 Timer pins.  (per (b), above)  You can then program this GPIO Output to a known "high" duration - so that you can quickly/easily verify the Timer processing results.

    d) Upon the "rising edge" Timer's interrupt - read that Timer - and "log/store" the Timer's data Reg.  (This yields the signal's lead/beginning edge)

    e) Upon the "falling edge" Timer's interrupt - read that Timer - and  "log/store" that Timer's data Reg.  (This yields the signal's trail/ending edge)

    f) Difference between the stored results w/in (d) and (e) yields the duration of the time your signal remained high.  (assumes your signal was not "high" so long as to exceed the capacity of the timer - which would result in a roll-over)  Charts w/in the Timer section of MCU manual describe maximum time capacity of the timer when configured in multiple modes.  Read, understand and comply.

    g) Upon your execution and confirmation of this methodology - your replacement of your MCU GPIO Output signal with your Sensor should be far less "eventful."

    If you wish you can list your code which implements this sequence of operation - and report your results.  Advise that you be, "on guard" for those Ports which may set-up and configure "special pins" to a "hard to change" special status.  (that's outside your topic - we neither seek nor want that intrusion at this time)  I'd look for a "higher order" Port (usually less "special pin default" burdened) which contains both Timer "A" and Timer "B" (from same Timer - and w/in same Port)

    Believe this is sufficiently detailed to enable your attempt...

     

  • It will be very helpful if u provide code for process using interupt...

  • Preyash Vashi said:
    It will be very helpful if u provide code

    Couple of minutes work for me - but such deprives you of the hunt/discovery/joy of, "how to do it."  (that is the goal - mais non?)

    Refer again to SW-DRL-UG - Interrupt chapter - toward the end are code examples.  (always minus the necessary config/set-up) 

    Then - woven throughout StellarisWare are multiple examples - look specifically @ Timers - much will reveal.  Myself/others here are not big fans of "cook-book" - imho you've received "pretty fair" guidance - and must now further fulfill your part of the bargain... 

    Roadmap I've posted (btw - "not" requiring you to consult local FAE) should drive you toward success.  Bit disappointing that detailed (a-g) guide receives zero comment/question - subverted by classic "do my homework" request.  (which is always rejected...)

     

  • You could do it precisely using a timer and interrupt. 

    I guess the following steps of pseudo code will give you the solution

    • Give the sensor data to GPIO pin
    • Also use another GPIO pin to contol the Ultrasonic Range Finder
    • Make the controlling pin as logic 1 and start one of the timers
    • When timer counts approximately to 10us an timer interrupt could be generated and use this to switch off the controlling GPIO pin 
    • Now start another timer of Arm Cortex M-4
    • Use pin-change interrupt of this pin to stop the timer
    • The count value of the new timer will be your solution
    Guess the solution will be effective.
  • Anand Baskaran1... I have already done that and...In my 3rd post i have written the code for that....

    But i am facing some problem with reading the input......It will be helpful if u provide me with some code for reading the input from my URF(using interupt or using polling the pin PE4 as i use in my code...).....and count the period of Echo i get from my sensor....

    thanx