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.

Compiler/TM4C1294NCPDT: GPTM configuration: timer in upward mode

Part Number: TM4C1294NCPDT

Tool/software: TI C/C++ Compiler

hola! buen dia a todos!, Tengo unas dudas acerca de como configurar el timer empleando las bibliotecas de TIVAWARE. Ya revise los ejemplos que proporcionan el fabricante, ahora quiero saber como puedo hacer que este retardo lo pueda configurar de manera ascendente de hecho este es mi codigo:

#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c1294ncpdt.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "inc/hw_memmap.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"

//Variables globales
bool state;

void Timer0IntHandler(void)
{
    TimerIntClear(TIMER0_BASE,TIMER_TIMA_MATCH);

    if(state==true)
    {
        GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0|GPIO_PIN_1,0x03);
        state=false;
    }
    else
    {
        GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0|GPIO_PIN_1,0x00);
        state=true;
    }
}

void main(void)
{
    //Habilita el modulo GPIO N
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
    //Espera que el modulo GPIO N este listo
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION));

    //Configuramos el puerto N 0 y 1 como salidas
    GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,GPIO_PIN_0|GPIO_PIN_1);

    //Habilitamos el TIMER0
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    //Esperamos a que el modulo TIMER0 este listo
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0));

    //Configura el Timer para 16 bits en modo periodico
    TimerConfigure(TIMER0_BASE,TIMER_CFG_A_PERIODIC_UP);
    //Carga el valor de Timeout
    TimerMatchSet(TIMER0_BASE,TIMER_A,65535);
    //Activa la interrupcion time out
    TimerIntEnable(TIMER0_BASE,TIMER_TIMA_MATCH);
    TimerIntRegister(TIMER0_BASE,TIMER_A,Timer0IntHandler);
    IntEnable(INT_TIMER0A);
    IntMasterEnable();
    TimerEnable(TIMER0_BASE,TIMER_A);
/*****************************************PROGRAMA PRINCIPAL*****************************************************/
    while(true);
}
I assumed that something similar to the example only that using the match register, but it doesn't work for me and another doubt is how I can use the prescaler here because at register level I can do it, but using the TIVAWARE library I don't have the slightest idea.

The teacher explained to us more or less some peripherals not all, apart from the SPMU298a manual, is there any book or page where I can help me to understand the TIVAWARE library?

Thank you!! and excuse my questions

  • Hello Antouriel,

    I was not able to understand the first half of your post which I think has your problem statement in it. Can you please re-post that in English? Thank you.

    Regarding TivaWare library, the example projects and SPMU298 are the best way to go. You can look at both the peripherals/timer folder and also some timer examples for LaunchPad in the latest TivaWare (2.2.0.295).

  • There's an apology, I'm sorry! I'm rewriting the first part:

    "Hello! Good morning, everyone! I have some questions about how to set the timer using the TIVAWARE libraries. I already checked the examples provided by the manufacturer, now I want to know how I can make this delay configurable in an ascending way in fact this is my code:

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/tm4c1294ncpdt.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/timer.h"
    #include "driverlib/interrupt.h"

    //Variables globales
    bool state;

    void Timer0IntHandler(void)
    {
        TimerIntClear(TIMER0_BASE,TIMER_TIMA_MATCH);

        if(state==true)
        {
            GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0|GPIO_PIN_1,0x03);
            state=false;
        }
        else
        {
            GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0|GPIO_PIN_1,0x00);
            state=true;
        }
    }

    void main(void)
    {
        //Habilita el modulo GPIO N
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
        //Espera que el modulo GPIO N este listo
        while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION));

        //Configuramos el puerto N 0 y 1 como salidas
        GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,GPIO_PIN_0|GPIO_PIN_1);

        //Habilitamos el TIMER0
        SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
        //Esperamos a que el modulo TIMER0 este listo
        while(!SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0));

        //Configura el Timer para 16 bits en modo periodico
        TimerConfigure(TIMER0_BASE,TIMER_CFG_A_PERIODIC_UP);
        //Carga el valor de Timeout
        TimerMatchSet(TIMER0_BASE,TIMER_A,65535);
        //Activa la interrupcion time out
        TimerIntEnable(TIMER0_BASE,TIMER_TIMA_MATCH);
        TimerIntRegister(TIMER0_BASE,TIMER_A,Timer0IntHandler);
        IntEnable(INT_TIMER0A);
        IntMasterEnable();
        TimerEnable(TIMER0_BASE,TIMER_A);
    /*****************************************Main program*****************************************************/
        while(true);
    }

    I assumed that something similar to the example only that using the match register, but it doesn't work for me and another doubt is how I can use the prescaler here because at register level I can do it, but using the TIVAWARE library I don't have the slightest idea.

    The teacher explained to us more or less some peripherals not all, apart from the SPMU298a manual, is there any book or page where I can help me to understand the TIVAWARE library?"

  • Hello Antouriel,

    No worries, thanks for posting a translated version!

    Regarding how to set the prescale, you can use the following API:

        TimerPrescaleSet(TIMER0_BASE, TIMER_A, 0xFF);

    That is set to max out the prescaler, you can use anything 0x00 to 0xFF as an input for it.

    I don't see the general load call either, only the match one, so for loading the timer at configuration time, you would use this:

        TimerLoadSet(TIMER0_BASE, TIMER_A, 0xFFFF);

    I am not entirely sure what you mean by making the delay in an 'ascending' manner. If you are trying to systematically increase the delay time, then you would want to use your main while routine to re-load new match value with TimerMatchSet. If needed you can pause the timer with TimerDisable.