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.

CCS/TM4C123GH6PM: Sensitive button

Part Number: TM4C123GH6PM

Tool/software: Code Composer Studio

Hi, 

i am new starting to learn about timers and push buttons.

My problem is that i want to implement a sensitive buton. If the pushed time is bellew 1s turn on a led. But i always end up in FaultISR().

can you please help me to solve it?

Regards.

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h" // Definicion de nombres de interrupciones (ej. INT_TIMER0A))
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_timer.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h" // Definicion de funciones de interrupcion (Int...())
#include "driverlib/gpio.h"
#include "driverlib/timer.h" // Definicion de funciones de Timer (Timer..())
#define F_CPU 16000000

const double temp = 1.0/40.0;

//Stores the pulse length
volatile uint32_t pulse=0;

//Tells the main code if the a pulse is being read at the moment
volatile uint8_t echowait=0;
// Programa principal
int main(void)
{
  uint8_t ui8LEDS=0;
  uint32_t ui32Period;
  // Configura reloj del sistema a 40MHz (PLL a 200MHz/5=40MHz)
  SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

  // Configuracion de puerto GPIOF (LEDs)
  // Habilita Puerto F
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  // Configura pines PF1, PF2, y PF3 como salidas (control de LEDs)
  GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);

  // Y apaga los LEDs
  GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);

  // Configuracion TIMER0
  // Habilita periferico Timer0
  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
  // Configura el Timer0 para cuenta periodica de 32 bits (no lo separa en TIMER0A y TIMER0B)
  TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC_UP);

  // Periodo de cuenta de 0.05s. SysCtlClockGet() te proporciona la frecuencia del reloj del sistema, por lo que una cuenta
  // del Timer a SysCtlClockGet() tardara 1 segundo, a 0.5*SysCtlClockGet(), 0.5seg, etc...
   ui32Period = (SysCtlClockGet()/10)/2;
  // Carga la cuenta en el Timer0A
  TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period-1);

  // Habilita interrupcion del modulo TIMER
  //IntEnable(INT_TIMER0A);
  // Y habilita, dentro del modulo TIMER0, la interrupcion de particular de "fin de cuenta"
  //TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
  // Habilita permiso general de interrupciones el sistema.
  ButtonsInit();

  GPIOIntClear(GPIO_PORTF_BASE,GPIO_PIN_4|GPIO_PIN_0);
  GPIOIntEnable(GPIO_PORTF_BASE,GPIO_PIN_4|GPIO_PIN_0);
  GPIOIntTypeSet(GPIO_PORTA_BASE,GPIO_PIN_0| GPIO_PIN_4,GPIO_BOTH_EDGES);

  IntEnable(INT_GPIOF);

  IntMasterEnable();
  // Activa el Timer0A (empezara a funcionar)
  TimerEnable(TIMER0_BASE, TIMER_A);

  while(1)
  {

       if(echowait != 1){

           if(pulse < 1000000){
              GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, ~GPIO_PIN_1);

           }

         while(echowait != 0);
          pulse =(uint32_t)(temp * pulse);

       }

         SysCtlDelay(400000);
  }
}


void RutinaISR(void)
{
    uint32_t status;


    status=GPIOIntStatus(GPIO_PORTF_BASE,true);

    if(status&GPIO_PIN_4){
        TimerEnable(TIMER0_BASE,TIMER_A);
         echowait=1;


    } else {
            pulse =TimerValueGet(TIMER0_BASE, TIMER_A);
            TimerDisable(TIMER0_BASE,TIMER_A);
            echowait=0;
        }



    GPIOIntClear(GPIO_PORTF_BASE,GPIO_PIN_4|GPIO_PIN_0);
    TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
}