The Signal Measurement Timer (SMT) capability is a 24-bit counter with advanced clocking and gating logic, which can be configured for measuring a variety of digital signal parameters such as pulse width, frequency and duty cycle, and the time difference between edges on two signals.
Syntax:
SETSMT1PERIOD ( 4045000 ) ' 1.000s period ' a perfect internal clock would be 4000000 SETSMT2PERIOD ( 9322401 ) ' 4.600s period InitSMT1(SMT_FOSC,SMTPres_1) InitSMT2(SMT_FOSC4,SMTPres_8) On Interrupt SMT1Overflow Call yourSMT1InterruptHandler On interrupt SMT2Overflow Call yourSMT1InterruptHandler StartSMT1 StartSMT2
Command Availability:
Available on Microchip microcontrollers with the SMT timer module.
This command set supports the use of the SMT as a 24-bit timer only.
Microchip PIC Microcontrollers have either 1 or 2 Signal Measurement Timers (SMT). A 24-bit timer allows for very long timer periods/high resolution and can be quite useful for certain applications. SMT timers support multiple clock sources and prescales. Interrupt on overflow/match is also supported.
SMT timers will "overflow" when the 24-bit timer value "matches" the 24-bit period registers.
The timer period can be precisely adjusted/set by writing a period value to the respective period register for eact timer.
The maximum period is achieved by a period register value of 16,777,215. 16,777,215 is the default value at POR. The timer period is also affected by the ChipMhz, TimerSource and Timer Prescale.
The library supports "normal" timer operation of SMT1/SMT2. The library does not support the advanced signal measurement features.
Explanation:
Commands are detailed in the table below:
Command | Description | Example |
---|---|---|
|
Source can be one of the below: |
|
|
Source can be one of the below: |
|
|
Clears the timer. No parameter required. |
|
|
Clears the timer. No parameter required. |
|
|
Sets the timer to the specific value. The value can be 1 to 16777215 |
|
|
Sets the timer to the specific value. The value can be 1 to 16777215 |
|
|
Stops the timer. No parameter required. |
|
|
Stops the timer. No parameter required. |
|
|
Starts the timer. No parameter required. |
|
|
Starts the timer. No parameter required. |
|
|
Sets the timer period to the specific value. The value can be 1 to 16777215 |
|
|
Sets the timer period to the specific value. The value can be 1 to 16777215 |
|
Example 1 (Microchip Only):
This example will ..
#Chip 16F18855, 32 #option explicit #Include <SMT_Timers.h> #config CLKOUTEN_ON '' -------------------LATA----------------- '' Bit#: -7---6---5---4---3---2---1---0--- '' LED: ---------------|D5 |D4 |D3 |D1 |- ''----------------------------------------- '' #define LEDD2 PORTA.0 #define LEDD3 PORTA.1 #define LEDD4 PORTA.2 #define LEDD5 PORTA.3 #define Potentiometer PORTA.4 Dir LEDD2 OUT Dir LEDD3 OUT Dir LEDD4 OUT Dir LEDD5 OUT DIR Potentiometer In SETSMT1PERIOD ( 4045000 ) ' 1.000s periodwith the parameters of SMT_FOSC and SMTPres_1 within the clock variance of the interclock ' a perfect internal clock would be 4000000 SETSMT1PERIOD ( 9322401 ) ' 4.600s period with the parameters of SMT_FOSC4 and SMTPres_8 InitSMT1(SMT_FOSC,SMTPres_1) InitSMT2(SMT_FOSC4,SMTPres_8) On Interrupt SMT1Overflow Call BlinkLEDD2 On interrupt SMT2Overflow Call BlinkLEDD3 StartSMT1 StartSMT2 Do '// Waiting for interrupts LOOP Sub BlinkLEDD2 LEDD2 = !LEDD2 End SUB Sub BlinkLEDD3 LEDD3 = !LEDD3 End SUB
Supported in <SMT_Timers.h>