Hi,
I am working on TM4C1231E6PZ microcontroller and doing event counter operation.
I am not able to load value in timer register (using ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, 0); ) .
I configured it as up event counter mode for Timer1A. Rest all code with UART7 and timer 0 is working fine.
Can anyone help on this?
Kiran
code is as below.
void counter1_init()
{
//
// Enable the peripherals used by this example.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
//
// Configure PM0 as the CCP0 pin for timer 1.
//
ROM_GPIOPinTypeTimer(GPIO_PORTF_BASE, GPIO_PIN_2);
ROM_GPIOPinConfigure(GPIO_PF2_T1CCP0);
//
// Configure the timers in downward edge count mode.
//
ROM_TimerConfigure(TIMER1_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_COUNT_UP));
ROM_TimerControlEvent(TIMER1_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, 0);
//
// Enable the timer.
//
ROM_TimerEnable(TIMER1_BASE, TIMER_A);
}
I am sending rest of the code for reference.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "driverlib/rom.h"
#include "delay.h"
#include "init.h"
#include "actuator.h"
#include "lcd.h"
#include "rtc.h"
const unsigned char a_Msg1[85] ="MECHATRONICS SYSTEMS "\
" PRIVATE LIMITED. "\
" Ver. KBJNLACTV1.0 "\
" Date : 21/04/2017 ";
typedef unsigned char tBoolean ;
tBoolean bToggle;
unsigned char a_ASCII[10];
long int lCurrentCount=0,lOldCount = 5000;
int main(void)
{
unsigned long ulDirection;
long int lCount=0;
//
// Set the clocking to run directly from the crystal.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
init_pinconfig();
delay_ms(1);
init_lcd();
delay_ms(1);
clear_lcd();
display_lcd(a_Msg1);
delay_ms(1000);
timer0_init();
counter1_init();
uart7_init();
delay_ms(1);
while(1)
{
lCount = ROM_TimerValueGet(TIMER1_BASE, TIMER_A);
if(lCount != 0)
{
ulDirection = ROM_GPIOPinRead(GPIO_PORTF_BASE,DIRN);
if(ulDirection)
{
lCurrentCount = lCurrentCount + lCount;
}
else
{
lCurrentCount = lCurrentCount - lCount;
}
ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, 0);
decimal_to_ascii(lCount,6);
a_ASCII[6] = '\0';
display_lcd_line(PAGE2,a_ASCII);
}
if(bToggle) ROM_GPIOPinWrite(GPIO_PORTA_BASE, DIRN_RLY, DIRN_RLY_ON);
else ROM_GPIOPinWrite(GPIO_PORTA_BASE, DIRN_RLY, DIRN_RLY_OFF);
delay_ms(1000);
}
}
//*****************************************************************************
//
// The interrupt handler for the first timer interrupt.
//
//*****************************************************************************
void Timer0IntHandler(void)
{
//
// Clear the timer interrupt.
//
ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
bToggle = ~bToggle;
}
//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void
UART7IntHandler(void)
{
uint32_t ui32Status;
unsigned long ulUart7In;
//
// Get the interrupt status.
//
ui32Status = ROM_UARTIntStatus(UART7_BASE, true);
//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART7_BASE, ui32Status);
//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail(UART7_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
ulUart7In = ROM_UARTCharGetNonBlocking(UART7_BASE);
ROM_GPIOPinWrite(GPIO_PORTB_BASE, RS485, RS485_TX_ENABLE);
delay_ms(1);
ROM_UARTCharPutNonBlocking(UART7_BASE,ulUart7In);
delay_ms(1);
ROM_GPIOPinWrite(GPIO_PORTB_BASE, RS485, RS485_RX_ENABLE);
}
}
void init_pinconfig()
{
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
// Input pin configurations
ROM_GPIOPinTypeGPIOInput(GPIO_PORTK_BASE, GPIO_PIN_3); //AUTO
ROM_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2); //MANUAL
ROM_GPIOPinTypeGPIOInput(GPIO_PORTK_BASE, GPIO_PIN_1); //HANDLE
ROM_GPIOPinTypeGPIOInput(GPIO_PORTK_BASE, GPIO_PIN_0); //NOT_OP
ROM_GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_4); //REMOTE
ROM_GPIOPinTypeGPIOInput(GPIO_PORTG_BASE, GPIO_PIN_4); //PROXY DN
ROM_GPIOPinTypeGPIOInput(GPIO_PORTG_BASE, GPIO_PIN_5); //PROXY UP
HWREG(GPIO_PORTF_BASE+GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTF_BASE+GPIO_O_CR) |= GPIO_PIN_0;
ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_2); //ROTN
ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_3); //DIRN
ROM_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_2); //C1
ROM_GPIOPinTypeGPIOInput(GPIO_PORTH_BASE, GPIO_PIN_0); //C2
ROM_GPIOPinTypeGPIOInput(GPIO_PORTH_BASE, GPIO_PIN_1); //C3
ROM_GPIOPinTypeGPIOInput(GPIO_PORTH_BASE, GPIO_PIN_2); //C4
ROM_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_4); //C5
ROM_GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_7); //DOWN
ROM_GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_6); //STOP
ROM_GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_5); //UP
// Output pin configurations
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_3); //MOTOR_ON
ROM_GPIOPinWrite(GPIO_PORTA_BASE, MOTOR, MOTOR_OFF);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_4); //DIRN_RLY
ROM_GPIOPinWrite(GPIO_PORTA_BASE, DIRN_RLY, DIRN_RLY_OFF);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_5); //SD
ROM_GPIOPinWrite(GPIO_PORTA_BASE, SD, SD_OFF);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_3); //R1
ROM_GPIOPinWrite(GPIO_PORTE_BASE, ROW1, ROW1_DISABLE);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTJ_BASE, GPIO_PIN_2); //R2
ROM_GPIOPinWrite(GPIO_PORTJ_BASE, ROW2, ROW2_DISABLE);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_5); //R3
ROM_GPIOPinWrite(GPIO_PORTE_BASE, ROW3, ROW3_DISABLE);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_3); //SDA
ROM_GPIOPinWrite(GPIO_PORTG_BASE, SDA, SDA_SET);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_2); //SCL
ROM_GPIOPinWrite(GPIO_PORTG_BASE, SCL, SCL_SET);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_5); //485
ROM_GPIOPinWrite(GPIO_PORTB_BASE, RS485, RS485_RX_ENABLE);
// LCD Pin Configuration
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTH_BASE, GPIO_PIN_4); //RW
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTH_BASE, GPIO_PIN_5); //RS
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTH_BASE, GPIO_PIN_6); //RST
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTH_BASE, GPIO_PIN_7); //EN
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_1);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_2);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_3);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_4);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_5);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_6);
HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0xff;
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_7);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_3); //ON
ROM_GPIOPinWrite(GPIO_PORTB_BASE, LCD, LCD_ON); // LCD Module enable
}
void // The Timer0 init
void timer0_init()
{
//
// Enable the peripherals used by this example.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
//
// Enable processor interrupts.
//
ROM_IntMasterEnable();
//
// Configure the two 32-bit periodic timers.
//
ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet());
//
// Setup the interrupts for the timer timeouts.
//
ROM_IntEnable(INT_TIMER0A);
ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
//
// Enable the timers.
//
ROM_TimerEnable(TIMER0_BASE, TIMER_A);
}
void timer0_disable()
{
ROM_TimerDisable(TIMER0_BASE, TIMER_A);
}
void uart7_init()
{
//
// Enable the peripherals used by this example.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7);
//
// Enable processor interrupts.
//
ROM_IntMasterEnable();
//
// Set GPIO A0 and A1 as UART pins.
//
ROM_GPIOPinConfigure(GPIO_PE0_U7RX);
ROM_GPIOPinConfigure(GPIO_PE1_U7TX);
ROM_GPIOPinTypeUART(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Configure the UART for 115,200, 8-N-1 operation.
//
ROM_UARTConfigSetExpClk(UART7_BASE, ROM_SysCtlClockGet(), 19200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
//
// Enable the UART interrupt.
//
ROM_IntEnable(INT_UART7);
ROM_UARTIntEnable(UART7_BASE, UART_INT_RX | UART_INT_RT);
}