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:高速时的二进制计数器

Guru**** 2539500 points
Other Parts Discussed in Thread: EK-TM4C1294XL

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1098855/tm4c1294ncpdt-binary-counter-at-high-speed

零件号:TM4C1294NCPDT
主题中讨论的其他部件:EK-TM4C1294XL

您好,我有一个新问题。

我正在为粒子探测器构建一个前端电路,它有很多通道(256)。 所以我决定用模拟多路复用器 ADG732将32个通道分组,以便通过一个ADC进行读数。 对于ADC和PC接口,我决定使用板EK-TM4C1294XL。  

在定时方面,ADG732应根据5个逻辑控制输入A0-A4切换输出1us。 所以基本上,从MCU的那一面,我应该编程一个5位的二进制计数器,在一些引脚上输出它的值,并将引脚连接到ADG732上的A0-A4。 问题是我还不知道怎么做。  在我看来,一个(软件)循环,带有1增量和等待,不能保证定时条件。  

有什么建议?

非常感谢!

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好,

    问题是我还不知道如何正确执行此操作。  在我看来,一个(软件)循环,带有1增量和等待,不能保证定时条件。  [/引述]

     您可以设置1us超时的计时器。 每次计时器超时,都会产生中断。 在ISR中,您将把新的5位值写入 连接到ADG732多路复用控制输入的GPIO端口。  

     请参阅 C:\tiaWare_C_Series-Timer.Timer\Examples\Peripherals\timer周期性2.2 _16bit.c有关如何设置周期性计时器的示例。0.295  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    谢谢Charles,让我尝试一下这种方法。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    谢谢Charles。 下面是实施您的解决方案的代码:

    #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) {}
    }