PIC ReportExp7
PIC ReportExp7
Introduction:
This experiment looks at how timers and interrupts work in microcontrollers, which are essential
for keeping track of time and managing tasks. It explains how timers and interrupts are
programmed and set up in a microcontroller and shows how they help with task management.
The experiment provides useful insights for people interested in embedded systems and
microcontroller programming. Learning how to use timer interrupts to perform actions at specific
intervals. We did this by first using a button interrupt (CN) to rotate or count, then switching the
rotate action to a rotating action.
Tools Used:
• ChipKIT Pro MX7 processor board with USB cable
• Microchip MPLAB X IDE
• MPLAB XC32++ Compiler
• MPLAB Harmony Framework
Experimental Results
o Project Initialize:
We began the experiment by setting up a new project and performing the necessary
configurations in the following sequence:
• Set the System Clock (SYSCLK) to 80 MHz.
• Configured the Peripheral Bus Clock (PBCLK) to 10 MHz, achieved by applying a
postscaler with a division factor of 8.
rimental Results
An-Najah National University جامعة النجاح الوطنية
Faculty of Engineering and IT
كلية الهندسة وتكنولوجيا المعلومات
o Project Initialize:
• Configured the key device settings.
• Set up the I/O pins, with digital output pins connected to LEDs on pins RG12 - RG15.
Change Notification interrupt 8 (CN8) was assigned to BTN1 on pin RG6, while CN9
was assigned to BTN2 on pin RG7.
• Navigating to the options tab in MPLAB Harmony Configurator (MHC) and expanding
the configuration tree to access the drivers and timer settings.
• Enabling the "Use Timer Driver" option, setting the driver implementation to
"STATIC" and enabling interrupt mode.
• Setting the timer period to 29297, calculated using formula (1) for a desired period
of 0.75 seconds, a prescaler value of 256, and a PBCLK of 10 MHz.
o Code Implementation :
• Finally, we developed code to manage the actions triggered by pressing BTN1 or
BTN2. The first segment, linked to BTN1, was implemented for counting, while the
second segment, linked to BTN2, was for rotating. Before these core
implementations,
• two preliminary checks were conducted to ensure the buttons (BTNs) were properly
connected to the change notifications (CNs) and functioning as expected. The LEDs
responded by turning on or off depending on which button (1 or 2) was pressed,
confirming proper functionality. Additionally, a timer-driven counter was used to
verify the timer's performance, with its status displayed through the LEDs.
An-Najah National University جامعة النجاح الوطنية
Faculty of Engineering and IT
كلية الهندسة وتكنولوجيا المعلومات
In the predvious code, we have an ISR for the timer and CN interrupts for buttons
1 and 2. Each time a CN interrupt occurs, we check which button is pressed and set
a flag to 1 or 2 accordingly. When the timer interrupt occurs, we set the state to
perform the corresponding action based on the flag.
Conclusions:
The results of this experiment highlight the effectiveness of timers and change
notification interrupts in managing time-based events and quickly responding to
input changes. These features are highly valuable in embedded systems design,
enabling the development of advanced and reliable systems capable of executing
tasks with precision.
In conclusion, this experiment underscores the critical role that timers and change
notification interrupts play in embedded systems. Their ability to enhance the
functionality and performance of microcontroller-based systems further
demonstrates their significance in this field.