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.

TM4C1231E6PZ: TM4C1231E6PZ Event counter problem

Part Number: TM4C1231E6PZ

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);
}

  • Hi,

    I have applied encoder output to a counter as an input (Timer1-A)

    Also I have written below logic to avoid this problem (not able to load value in timer register (using ROM_TimerLoadSet (TIMER1_BASE, TIMER_A, 0); ) .

    lTimerACount = ROM_TimerValueGet(TIMER1_BASE, TIMER_A); // read counter value
    if(lTimerACount >= lPreviousCount) // chech whether there is any count in timer reg.
    {
    lCountDiff = lTimerACount - lPreviousCount;
    }
    else
    {
    lCountDiff = (65535 - lPreviousCount) + lTimerACount;
    }

    if(lCountDiff != 0)
    {
    lCountDiff = lCountDiff * 10;
    DIRN = ROM_GPIOPinRead(GPIO_PORTF_BASE,ENCODER_DIRN);
    if(DIRN) // CHECK DIRECTION INPUT
    {
    bMovingUp = 1;
    liActualCount += lCountDiff;
    if(liActualCount >= ulMaxCount) liActualCount = ulMaxCount;
    }
    else
    {
    bMovingDown = 1;
    liActualCount -= lCountDiff;
    if(liActualCount <= 0) liActualCount = 0;
    }

    if(!bUpdate)
    {
    liCurrentCount = liActualCount;
    bCalculate = 1;
    }
    uiLcdOffDelay = 0;
    lPreviousCount = lTimerACount; // load current count into old count
    }

    But want to load 0 count in timer register as soon as copy to temporary variable lTimerACount .

    Any guidance on above problem?

    Regards,

    Kiran
  • Hi Kiran,

     Sorry, looks like your post was missed for several days. Note that in input edge-count mode the GPTMnnILR must be greater than GPTMnPMR. 

    In up-count mode,
    the timer counts from 0x0 to the value in the GPTMTnMATCHR and GPTMTnPMR registers. Note
    that when executing an up-count, that the value of GPTMTnPR and GPTMTnILR must be greater
    than the value of GPTMTnPMR and GPTMTnMATCHR.

    Please also refer to the below post which will help answer your question.

  • Charles - might you (in a free moment) comment upon (multiple) posters' "penchant" for "doubling up" on the MCU's Part number for presentation in their "Subject/Title" line?

    (i.e. TM4C1231E6PZ: TM4C1231E6PZ) Seems pointless - more effort in clearer presentation of their issue - seems far more productive...
  • Hi cb1,

     Yes, I do find from time to time that some posts will have the part number mentioned in the title twice. I'm not sure if posters see what I see in the below post entry. In the E2E thread title field, there is a prenote that says "if the part number is entered above, do not repeat..." I'm not too sure if sometimes the prenote will blank out when a new post is created. 

  • Charles - you've a "future" as a detective (along w/being skilled EE) I am sure! I never/ever noted that. (likely because I wrote & posted "Forum Guidelines" several times - to great (i.e. NO) response.)

    If that proves the cause of, "Part No. doubling" I apologize to this poster. Most always the Subject Lines are rushed - not compelling - and poster's must realize that they have the responsibility to SELL their Posts! (otherwise - they are (almost) begging - which is not good!)