The Signal Measurement Timer (SMT) is a powerful new timing peripheral found on several of the newer PIC® MCU devices, such as the PIC16F18877 and PIC18F67K40 families. Each SMT is a 24bit timer that can operate in one of several modes:
* Timer - A simple 24bit timer, similar to the Timer0 or Timer1 peripheral.
* Gated Timer - Like timer mode above, but only increments when the signal GPIO signal is high.
* Period and duty cycle measurement - Like gated timer, increments a counter when the signal GPIO signal is high. But when the signal GPIO goes low, the timer value is stored for future use and the counter is reset back to 0.
* High and low measurement - Similar to Period and duty cycle mode above, but resets and stores on every signal edge.
* Window Measurement - akin to period and duty cycle measurement above, but measures time between two rising edge signals on the window GPIO pin.
* Gated window measurement - Like window measurement above, but time only increments when the signal GPIO pin is high.
* Time of flight - Similar to window measurement, but timing starts when the window GPIO pin goes high and the timer is stored and reset to 0 when the window GPIO pin or signal GPIO pin goes high.
* 24bit capture - Simply stores the timer value when the window GPIO pin changes state.
* 24bit counter - Counts all the rising edges of the signal GPIO pin.
* Gated counter - Comparable to the 24bit counter mode, but only increments when the window GPIO pin is high.
* Windows counter - Like the gated counter mode, but a rising edge of the window GPIO pin will store the existing timer counter and then reset it to 0.
The CCS C Compiler has been updated to add a library that allows for controlling, configuring and using the SMT in your PICmicro C projects. The functions that have been added are setup_smtX() (or setup_smt1() to setup the first SMT peripheral), smtX_status(), smtX_start(), smtX_stop(), smtX_update(), smtX_reset_timer(), smtX_read() and smtX_write(). For more help, refer to the CCS C Compiler Help file for documentation.
Here is an example of using the Timer mode to blink an LED at a 1Hz rate:
#define LED_PIN PIN_B4
#define SMT_PERIOD (getenv("CLOCK") - 1)
setup_smt1(SMT_ENABLED | SMT_MODE_TIMER | SMT_CLK_FOSC, SMT_PERIOD);
The CCS C Compiler also provides 2 full example programs showing how to use the SMT, which can be found in the examples directory of the CCS C Compiler. First ex_smt_timer.c which is an example of using the SMT peripheral in Timer mode to toggle an I/O pin, and second ex_smt_period_duty.c which is an example of using the SMT peripheral in Period and Duty Cycle Acquisition mode to determine the period and duty cycle of an input signal.
Like us on Facebook. Follow us on Twitter.
CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.
PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.