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.

TM4C1294NCPDT: Binary counter at high speed

Part Number: TM4C1294NCPDT
Other Parts Discussed in Thread: EK-TM4C1294XL

Hello, I have a newbie question.
.
I'm building a front-end circuit for a particle detector with a lot of channels (256). So I decide to group 32 channels for readout by one ADC, using the analog multiplexer ADG732. For ADC and PC interface, I decide to use the board EK-TM4C1294XL. 

In terms of timing, each 1us, the ADG732 should switch the output according to the 5 logic control inputs A0-A4. So basically, from the MCU side, I should program a 5-bit binary counter, output its value on some pins and connect the pins to A0-A4 on ADG732. The problem is I don't know how to properly do this yet. It seems to me that a (software) loop, with 1-increment and wait, will not guarantee the timing condition. 

Any suggestion?

Many thanks!

  • Hi,

    The problem is I don't know how to properly do this yet. It seems to me that a (software) loop, with 1-increment and wait, will not guarantee the timing condition. 

      You can set up a timer with a 1us timeout. Each time the timer timeouts, it will generate an interrupt. In the ISR, you will write your new 5 bit value to a GPIO port that is  connected to your ADG732 mux control inputs. 

      See C:\ti\TivaWare_C_Series-2.2.0.295\examples\peripherals\timer\periodic_16bit.c example on how to set up a periodic timer. 

  • Thanks Charles, let me try this approach.

  • Thanks Charles. Below is the code implementing your solution:

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/fpu.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/timer.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    
    
    //*****************************************************************************
    // SELECT BITS
    //*****************************************************************************
    uint32_t g_ui32SelectBits;
    
    //*****************************************************************************
    // The error routine that is called if the driver library encounters an error.
    //*****************************************************************************
    #ifdef DEBUG
    void
    __error__(char *pcFilename, uint32_t ui32Line) {}
    #endif
    
    //*****************************************************************************
    // The interrupt handler for the first timer interrupt.
    //*****************************************************************************
    void Timer0IntHandler(void) {
        // Clear the timer interrupt.
        ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    
        // Output the value of SELECT bits to PE0-4 pins
        GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4, g_ui32SelectBits);
    
        // Update select bits
        g_ui32SelectBits++;
    }
    
    //*****************************************************************************
    // Configure the UART and its pins.  This must be called before UARTprintf().
    //*****************************************************************************
    void ConfigureUART(void) {
        // Enable the GPIO Peripheral used by the UART.
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
        // Enable UART0
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    
        // Configure GPIO Pins for UART mode.
        ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
        ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
        ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        // Use the internal 16MHz oscillator as the UART clock source.
        UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    
        // Initialize the UART for console I/O.
        UARTStdioConfig(0, 115200, 16000000);
    }
    
    int main(void) {
    
        // Initialize SelectBits
        g_ui32SelectBits = 0;
    
        // Enable lazy stacking for interrupt handlers.  This allows floating-point
        // instructions to be used within interrupt handlers, but at the expense of
        // extra stack usage.
        ROM_FPULazyStackingEnable();
    
        // Set the clocking to run PLL
        ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    
        // Initialize the UART and write status.
        ConfigureUART();
        UARTprintf("Hello, world!\n");
    
        // Enable the GPIO port that is used for the on-board LED.
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    
        // Enable the GPIO pins for SELECT pins
        MAP_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4);
    
        // 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() / 1000000) - 1);
    
        // Setup the interrupts for the timer timeouts.
        ROM_IntEnable(INT_TIMER0A);
        ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    
        // Enable the timers and start infinite loop
        ROM_TimerEnable(TIMER0_BASE, TIMER_A);
        while(1) {}
    }