You are on page 1of 2

Encoder.

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/tm4c123gh6pm.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"
1#include "inc/hw_timer.h"
#define Tmpmax 39999999
#define dØ 0.314159
volatile float contador = 0;
volatile float dt = 0.00000;
volatile float W;

void PERIFERICOS(void){
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
}

void GPIO(void){
GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1); 25}

void TIMER(void){
TimerConfigure(TIMER0_BASE, TIMER_CFG_ONE_SHOT_UP);
TimerLoadSet(TIMER0_BASE, TIMER_A, Tmpmax);
}

void INTERRUPCION(void){
GPIOIntTypeSet(GPIO_PORTD_BASE, GPIO_PIN_0, GPIO_FALLING_EDGE);
GPIOIntEnable(GPIO_PORTD_BASE, GPIO_INT_PIN_0);
IntEnable(INT_GPIOD);
IntMasterEnable();
}

//PIN PD0 --> CLK


//PIN PD1 --> DT
void MEDIR_VELOCIDAD(void){
GPIOIntClear(GPIO_PORTD_BASE, GPIO_INT_PIN_0);
contador = TimerValueGet(TIMER0_BASE, TIMER_A); // Se determina
cuantos numeros se han contado
HWREG(TIMER0_BASE + TIMER_O_TAV) = 0; //Reiniciar el contador
TimerEnable(TIMER0_BASE, TIMER_A);
}

int main(void){
SysCtlClockSet(SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_1
6MHZ| SYSCTL_SYSDIV_5);//40Mhz
PERIFERICOS();
GPIO();
TIMER();
INTERRUPCION();
while(1){
dt = contador/40000000;
W = dØ/dt;
}
}

Page 2

You might also like