"pragma cpu_heartbeat" Statement

The system heartbeat is an interrupt that is triggered at a regular interval, often many times a second. The heartbeat is used to monitor and control various system functions.

The "pragma cpu_heartbeat" statement tells the compiler how many heartbeat interrupts should be produced per second.

The heartbeat interrupt is generated via the hardware timer (timer 0). The minimum (smallest) number of heartbeat interrupts attainable is dependent on the oscillator used to generate the CPU clock. This is because timer 0 is restricted to a maximum delay of 65536 clock ticks.

For a PIC running at 4MHz this equates to 4000000 / 4 / 65536 interrupts per second that is 15 interrupts per second.

For a PIC running at 20MHz this equates to 20000000 / 4 / 65536 interrupts per second that is 76 interrupts per second.

syntax

pragma cpu_heartbeat 20
The "pragma cpu_heartbeat" statement provides the heartbeat value for use by the rest of the program through the CPU_HEARTBEAT manifest constant. The programmer may use this constant like any other constant.
e.g.

	x = CPU_HEARTBEAT / 2