4. Event counting and watchdog timer
Requirement: Count the number of internal and external events that occur within one second.
Solution: This application combines a frequency generator and an event counter. Use counters 11 and 12 (cascaded by default) as 32-bit timers, and generate a 1-second timing signal using their precise 8MHz clock. Meanwhile, using counter 1 as the event counter, the clock source is the external event signal ECLK1, and the gate signal is controlled by COUP12 (enabled within 1 second). When COUP12 outputs a high level with a width of 1 second, counter 1 starts counting external events. After 1 second, the gate control signal goes low and counter 1 stops counting. At this time, the value of counter 1 is read, which is the total number of events in that second. This mechanism can be extended to a watchdog timer: if the system does not "feed the dog" within the set time (such as resetting counter 12 through software), counter 12 will generate an interrupt (INT1), triggering a system reset or alarm. This fully utilizes the dual interrupt system of the board, providing a highly reliable system monitoring method.
Key points of software development and debugging
Initialization process: Any application must first call _8554-INitial (or W_8554-INitial under Windows). This function will fill a PCI-INFO structure, which contains the key base address (for all subsequent register operations) and the assigned IRQ number.
Cascade configuration sequence: When configuring cascade counters in software, they should be set in the order from back to front. For example, when configuring the cascading of counters 1->2->3, the mode and initial value of counter 3 should be configured first, followed by counter 2, and finally counter 1. This can avoid unexpected output jumps during the configuration process.
Interrupt Service Program: In the DOS environment, the Interrupt Service Program (ISR) needs to be written by the user and hooked through _8554-INT_Enable. In ISR, you must call _8554_Get_IRQ_Status to determine which interrupt source triggered the interrupt, and call _8554_CLR_IRQ1 or _8554_CLR_IRQ2 to clear the interrupt status after processing, otherwise the interrupt source cannot be triggered again.
De jitter configuration: When using an external clock or external interrupt in a strong electromagnetic interference (EMI) environment, it is strongly recommended to enable the de jitter function through jumper wires and select the appropriate sampling clock through _8554_S_TDBCLK. Sacrificing small response delays in exchange for system stability and data accuracy is often worthwhile in industrial settings.
