Examples and register assignments
4.2 Examples
SIMATIC PCIe DIO4
Compact Operating Instructions, 11/2011, A5E03493449-01
19
●
GSR.CIF: Evaluate CxSR.IF. Evaluate CxSR.OIF, CxSR.CEIF, CxSR.CGIF and
CxSR.CSIF and delete these interrupts through writing.
●
GSR.EIF: External error has occurred, e.g. missing output voltage or overload/short
circuit: Remedy the error and delete the GSR.EIF through writing.
Check GSR.IF to see if all interrupts have been processed.
Example 6: Measuring frequency at input 3
In this example we use counter 3 (C3) to measure the frequency of input 3. The rising edge
is used as time. Program C3 as follows:
Incrementing, clear + capture with rising edge of input 3.
●
Calculating C3 address: C3BASE = BASE + (3 * 0x100) = BASE + 0x1300.
●
Programming event "Up": C3TR0 = 0x0100 (Source 0x01 = Always on)
●
Programming event "Clear": C3TR2 = 0x2B08 (Source 0x2B = input 3, 0x08 = rising
edge)
●
Programming event "Capture": C3TR4 = 0x2B08 (Source 0x2B = input 3, 0x08 = rising
edge)
●
Enabling C3: C3CR.EN |= 1
The frequency is then calculated as follows: f
3
=1 / ( (1) * 16 ns)
Example 7: Measuring pulse length at input 2
In this example we use counter 1 (C1) to measure the pulse length of the signal at input 2.
Program C1 as follows:
Incrementing, clear with rising edge, capture with falling edge of input 2.
●
Calculating C1 address: C1BASE = BASE + (1 * 0x100) = BASE + 0x1100.
●
Programming event "Up": C1TR0 = 0x0100 (Source 0x01 = Always on)
●
Programming event "Clear": C1TR2 = 0x2A08 (Source 0x2A = input 2, 0x08 = rising
edge)
●
Programming event "Capture": C1TR4 = 0x2A0A (Source 0x2A = input 2, 0x0A = falling
edge)
●
Enabling C1: C1CR.EN |= 1
The pulse length is then calculated as follows: t
pw2
= ( 1) * 16 ns