Microchip

Microchip Technology Inc. is a leading provider of microcontroller and analog semiconductors, providing low-risk product development, lower total system cost and faster time to market for thousands of diverse customer applications worldwide. Headquartered in Chandler, Arizona, Microchip offers outstanding technical support along with dependable delivery and quality.

Pillbox Alarm Application

Pillbox Alarm Software Overview

The pillbox alarm application allows the user to set up to four different daily alarm times, as reminders to take pills at required times. To set up the current time and the alarm times, the user must place the SET/RUN slide switch in the SET position. As shown in the photograph below, an Organic Light-Emitting Diode (OLED) display and four pushbuttons are used to implement a simple interface for adjusting the alarms.

Figure 1 Photograph of the Pillbox Alarm Software Running on the P4 Board

After alarm setup is complete, the user places the SET/RUN slide switch in the RUN position and the OLED display is shut off to conserve power. When an alarm occurs, a piezoelectric buzzer generates a pulsating sound and the LED associated with that alarm flashes until the adjacent pushbutton is pressed to reset the alarm.

Pillbox Alarm Software Description

A flowchart for the pillbox alarm application software is shown in the figure below.

Figure 2 Pillbox Alarm Application Flowchart

After a battery is inserted in the P4 board, the software starts by performing general initialization. The ports and peripherals required by the application are set up. As a simple start-up test, each red LED is turned ON for 50 milliseconds, and the piezoelectric buzzer is driven with a 4 kHz signal for five milliseconds to produce a short chirp.

Next, the slide switch on the P4 board is checked to determine if it is in the RUN or SET position. If the switch is in the RUN position, the device goes into STANDBY sleep mode until it is awakened by a pin change interrupt. Once the switch is in the SET position, the CPU enters a forever loop (Loop A on the flowchart) that starts with the initialization of the OLED and Two-Wire Interface (TWI). The TWI is used for sending data to the OLED.

After the OLED and TWI have been initialized, the software enters a loop (Loop B on the flowchart) that starts by checking the position of the slide switch. If the slide switch is in the RUN position, the code escapes the loop and continues to another section of code. On the other hand, if the slide switch is in the SET position, the software stays in Loop B. This loop is responsible for implementing the alarm/time setting interface using the OLED display and four push buttons.

When Loop B is exited, Loop C is entered. Loop C starts by checking the position of the slide switch. If the slide switch is in the SET position, the code escapes the loop and continues back to the beginning of Loop A. On the other hand, if the slide switch is in the RUN position, the software stays in Loop C.

Loop C is responsible for keeping track of time. It is also responsible for handling alarms by turning them ON or OFF at appropriate times.

Next, the RUN/SET switch is checked and the measure variable is checked. (The measure variable is updated in an interrupt service routine so that a new oscillator measurement is triggered every 15 minutes.) If the slide switch is still in the RUN position and it is not time for another oscillator measurement, alarms are checked and handled. Then the device is put into STANDBY sleep mode.

When the device is awakened, either by a periodic (three seconds) Real-Time Counter (RTC) interrupt or pin change interrupt, the flow returns to the top of Loop D where the slide switch and measure variable are checked. If the slide switch is in the SET position or the measure variable indicates that another oscillator measurement is needed, the flow returns to the top of Loop C. Otherwise, the flow remains in Loop D.

Power consumption is minimized in the software by keeping the device in STANDBY sleep mode most of the time, with only the OSCULP32K running to clock the RTC. Because all variables are stored in SRAM, no alarm settings are retained when the battery is removed or depleted.

Source: Microchip

Join the Conversation!

User must log-in to comment.

    Add Comment

    You must log-in to comment.