

To determine the quantity of pulses, we need to divide SMTF osc by the Frequency:Īs you can see, those values are floating or of the double variable type. And to get the frequency we use Equation 2: Thus, we have 1us for each clock pulse, that means if we have a period of 1ms we should have 1000 pulses with a constant period. We have an SMT clock of 1 MHz to determine the time we get: Then we set the clock to 16 MHz with an external crystal, and in the SMT module we set the Prescaler value to 4, and the period scale to 4. These measurements can’t be read directly, because the value in the counter is a Frequency.
#PIC SIGNAL MEASUREMENT TIMER PBP3 CODE#
For the single measurement, you have to select the polarity options to take measurements at the rising edge or stop at the falling edge.īITS 3 to 0: The operational mode is assigned by setting those bits.Īs you can see in the Code Listing below, we’re using a 20X2 LCD display to show period measurements. The operation of those bits is described as follows (the STxCON is the control register):īIT 7: Enables the SMT module if this bit is set to 0, the entire SMT is disabled.īIT 5: Stops the counter it’s used for interrupt options.īIT 4: Window input polarity for measurements at rising or falling edge.īIT 3: Input signal polarity enables measurements at rising or falling edge.īIT 2: Clock input polarity increments counter at rising or falling edge.īIT 7: Starts to get data from the counter clock if disabled, it doesn’t count.īIT 6: This bit lets us choose between two methods of operation: single measurement or take and repeat. We need to set both to take a measurement. There are two control registers for the SMT module.

Those registers are for initialization only, we have to select the clock and its input port, even if they’re selected on the SMT register. SMT1SIG = 0 Signal Input Select Register (we can use almost every pin as an SMT input in this case, SMTSIG1 is selected by default) SMT1CLK = %00000001 SMT Clock Selection Register (we select Fosc/4) The setting code for the SMT MODULE as a Period and Duty Cycle acquisition is:
#PIC SIGNAL MEASUREMENT TIMER PBP3 SOFTWARE#
We set in software a 50-ms delay after starting an acquisition. To understand how this counter and its registers work, we need to check the timing diagram.Īccording to the datasheet’s timing diagram, we have a delay before starting the counter for synchronization purposes the time depends on the internal or external clock. In this design, we’re using the second mode. The second mode can read and save the counter value settings, the GO and Interrupt acquisition, by just configuring the SMTxGO register. You can configure it to the rising edge of the signal to start reading, or go to acquisition and set the falling edge as an interrupt.


The first works as single acquisition, which can take the timer/counter contents. The Period and Duty Cycle mode has two modes of operation. Figure 2 shows the electronic schematic for this design. In this application, we use the SMT module in Period and Duty Cycle acquisition mode. The SMT can perform a variety of measurements such as Gated Timer, Period and Duty Cycle Acquisition, High and Low Measurement, Windowed Measurement, Gated Window measurement, Time of Flight, Capture, Counter, Gated Counter, and Windowed Counter. The module’s operation consists of reading data of a 24-bit timer/counter and transferring it to three registers called TMR, CPR, and PR.
