More PIC Microcontrollers:Protection Devices,Interrupts,Hardware Timers and In-Circuit Programming

Protection Devices

Internal timers are used to ensure a reliable start-up on power-up, after a reset or a short-term dip in the supply voltage. In the 16F690, the power-up timer provides a nominal delay of 64 ms to allow the power supplies to stabilize before the program execution begins. The watchdog timer allows the chip to reset itself automatically if the program execution fails to follow the normal sequence, thereby improving overall reliability. Brownout protection allows the chip to reset in an orderly fashion if the power supply fails for a short period. Full details, including a block diagram, are provided in each chip data sheet. Over time, these protective features are becoming more elaborate, so that, if they are properly applied, the overall reliability of PIC applications is improved, at the expense of the firmware becoming more complex.

Interrupts

An interrupt is an internally or externally generated signal, which forces the processor to suspend the current operation and execute a interrupt service routine (ISR). The ISR thus has a higher priority than the background process. PIC chips provide a variety of interrupt sources, for example, a change on a selected input, or a hardware timer timeout. There is an interrupt priority system available in the more advanced 18 series PICs; this allows the chip to be set up to ignore an interrupt source if a more important one is already active. In CISC microprocessors, multiple interrupt vectors are usually available, and a different ISR can be invoked for different interrupt sources. In the PIC, all interrupts have to be serviced via the single interrupt vector, located at address 004 in program memory. To differentiate between them and to determine the action required, the ISR needs to check the relevant control register flags, to find out which interrupt source is active, before branching to the required routine. As the number of peripheral devices increases, such as additional timers, serial ports and so on, the number of potential interrupt sources increases, making interrupt servicing via a single vector more complicated.

Hardware Timers

The number of hardware timers available generally increases with the chip complexity. They are either 8-bit or 16-bit counters, with prescalers or postscalers, which divide down the input or output of the counter to extend its range. If we take the motor program in Chapter 11 as an

example, we can see how additional hardware timers could have been utilized; the 20 ms time interval and the motor output cycle delay could both have been implemented as hardware operations, while the sensor pulse monitoring could have used RB0 interrupt. As well as simple counting and timing, the hardware timers can be configured to measure input intervals, generate timed outputs and drive output loads using pulse width modulation (PWM; see Section 12.3.1 below). Sometimes, independent clocks are associated with the timers and protective devices, so that they can continue to function when the main clock fails, or a different timebase is needed.

Sleep Mode

This is useful for terminating programs that do not loop continuously, suspending operations pending an interrupt or saving power in battery applications. The processor switches off the clock and disables most of its normal functions when the instruction SLEEP is encountered, with current consumed dropping to around 1 mA, or less in low-power devices (LP designation). Using SLEEP to terminate a program prevents it continuing into unprogrammed memory locations. These default to all 1s, which generally corresponds to a valid instruction code, ADDLW FF in 14-bit code (W, C, DC and Z all affected). If a program is not terminated with a SLEEP or GOTO instruction, the program will carry on to the end of memory, the program counter will roll over to zero and the program will restart. A hardware reset input or suitable interrupt will be needed if the application code is terminated with SLEEP.

In-Circuit Programming

The PIC microcontrollers use a common program downloading system, which consists of transferring the machine code in serial form via one of the data pins when the chip is in programming mode. Previously, the chip would be placed in a programming unit for downloading the application code, and then physically transferred to the application board. Now, the chip is normally programmed in circuit, where the chip can be left in circuit, reducing the risk of damage. It can then be programmed after the circuit has been manufactured, and reprogrammed at any time, via a six-pin on-board connector, which can be seen in the 16F690- based LPC board.The connector can be in the form of a SIL (PICkit 2/3) or RJ-11 (ICD 2/3) connector (see Chapter 7).

Leave a comment

Your email address will not be published. Required fields are marked *