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.

Read GPIO pin and count the period if high input is there

I want to resad the GPIO Pin and if there is high pulse at my pin.(from my sensor)...i want detect and count the time for which it stays high....

first i have to give the 10us high pulse and then read the pin...repeat whole sequence for at least every 65ms period...

I have written this code.....

#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"


unsigned long int count,ON_PERIOD[],j;
unsigned int i=0;
int main(void)
{

    ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
     GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_5);
        GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_4);


   



 
    while(1)
    {
       
   
        ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4,GPIO_PIN_4);     //make pin high for 10us for trigger
            SysCtlDelay(800);

            ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4,~GPIO_PIN_4);   //make it low for nearly 65 ms delay and read pin PE5
                        SysCtlDelay(1600000);

            j=3500000;
           while(j!=0)
           {
          while(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_5))       //read pin PE5 and if high start up cuounting
         {
           
                    ROM_TimerConfigure(WTIMER1_BASE,  TIMER_CFG_SPLIT_PAIR|TIMER_CFG_ONE_SHOT_UP);
        ROM_TimerEnable(WTIMER1_BASE, TIMER_A);

      
         }

             count=ROM_TimerValueGet(WTIMER1_BASE, TIMER_A);                            //after pin is low ...get the counter value
          j--;
 
    }
         
     
                               ON_PERIOD[i]=count;     // save count value in array
           i++;
  
}


}

and how can i check the the count value....what  i had done is right.....i don't know how can i check count value...

Please help....

thanx...

  • Timer + GPIO interrupt.

    Start timer on rising edge and stop it on falling edge.

    Learn how to do it at: http://processors.wiki.ti.com/index.php/Getting_Started_with_the_Stellaris_EK-LM4F120XL_LaunchPad_Workshop

    Datasheet is always usefull: http://www.ti.com/lit/ds/symlink/lm4f120h5qr.pdf

    Regards,
    Maciej