Introduction to Microcontrollers Lab Manual - Microchip
Introduction to Microcontrollers Lab Manual - Microchip
Introduction to Microcontrollers Lab Manual - Microchip
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
4.3 THE LAB<br />
4.2.4 Configuration Bits<br />
In general, most device configuration is done at run time by executing various instructions.<br />
However, there are some lower level functions that are only configurable at programming<br />
time. The WDT pre-scaler and post-scaler are two of the configuration<br />
settings that are only configurable at programming time.<br />
The <strong>to</strong>p three words of on-chip program memory in the PIC24FJ256GB110 family of<br />
devices are reserved for configuration information. On device Reset, the configuration<br />
information is copied in<strong>to</strong> the appropriate run-time registers.<br />
The Configuration bits are mapped starting at program memory location F80000h. Note<br />
that this address is beyond the user program memory space. In fact, it belongs <strong>to</strong> the<br />
configuration memory space (800000h-FFFFFFh), which can only be accessed using<br />
table reads and table writes and cannot be modified during normal code execution.<br />
Each lab has a file named config_bits_pic24fj256gb110.inc that includes the<br />
values used for every Configuration bit available in this family of devices. It also<br />
includes comments that describe each possible setting for each field.<br />
4.3.1 Objective<br />
Modify the file config_bits_pic24fj256gb110.inc <strong>to</strong> change the WDT period<br />
and write code <strong>to</strong> moni<strong>to</strong>r the Watchdog Timer. Use the controller itself <strong>to</strong> measure the<br />
Watchdog Timer period and compare <strong>to</strong> the expected values.<br />
Since the WDT time out will cause the processor <strong>to</strong> reset, a clever scheme is needed<br />
<strong>to</strong> measure the WDT time out. One way <strong>to</strong> do this is <strong>to</strong> configure a timer for a 1 ms<br />
period. Each time the timer expires, increment a local variable and send out the value<br />
of that variable through the UART <strong>to</strong> be moni<strong>to</strong>red using a PC terminal emula<strong>to</strong>r (like<br />
HyperTerminal).<br />
When the Watchdog Timer expires, it will reset the controller and thus the value of the<br />
timer will be reset <strong>to</strong> zero. By waiting for a but<strong>to</strong>n press on startup, it is possible <strong>to</strong> keep<br />
the controller from continuously overwriting the previous values in the terminal emula<strong>to</strong>r<br />
on power up. In this case, the last counter value that was written <strong>to</strong> the UART should<br />
be the WDT period.<br />
The UART needs <strong>to</strong> run at 115200 baud. At that baud rate, a character will take about<br />
87 us <strong>to</strong> be transmitted. This means there will be just enough time for some processing<br />
and <strong>to</strong> transmit about 10 characters between the 1 ms interrupts. If more characters are<br />
sent out the UART, then the resolution of the timer must increase. This will decrease<br />
the accuracy of the measurement, but may allow for a more informative message. This<br />
is a typical design trade-off that happens in real embedded system design.<br />
4.3.2 Pertinent Information<br />
The basic program flow is depicted in Figure 4-2.<br />
2011 <strong>Microchip</strong> Technology Inc. DS51963A-page 35