Embedded software to control the amplifiers
The software of the amplifier consists of two parts:
- The main program for controlling the switches of the amlifier like volume and input and display.
IR remote control system to
transmit data and receive and decode data.
MCU main program flow
The software contains an initialisation step which configures all ports of the controller, sets the required interrupts, clears all interrupt flags, restores volume settings from EEPROM and initializes the display followed by a welcome message. In case the restored volume exceeds a predefined value, the volume is decreased to a standard listening value and a LED is illuminated.
Source: initial C- program by E van de Logt.
The main routine handles all display updates and writes the serial data to the amplifier chip. A timer is used to jump to the interrupt service routine (ISR) of the controller. This timer overflows every 200ms which enables a repeated key press activity. By doing this, the user does not need to press the keys repeatedly to increase the volume. The ISR scans every 200ms the keys on the ports (after a 15 ms key debounce) to find out if the volume must be increased or decreased. Key variables are updated and flags are set. The mute switch activity is implemented with the "change on port" feature of the controller. Polling the corresponding flag in the ISR, controls the mute activity. If a change is valid the display, programmable amplifier and EEPROM are updated. The Mute function overrides any volume key press and EEPROM write action. During EEPROM write, the global interrupt bit is cleared to be sure that data is not changed during writing.
MCU remote controller flow
The software contains an initialisation step which configures all ports of the controller, sets the required interrupts and clears all interrupt flags. The main routine is very simple; it keeps the processor in sleep mode untill a key is pressed on the remote controller. To force an interrupt during sleep all driving colums are low. With the pull ups enabled on the sensing rows a level change is forced to one of the rows. This creates the interrupt and it jumps to the ISR. The only interrupt source used is the "change on port" interrupt. Once in the ISR the key pad matrix is scanned for the pressed key. This is done using simple static row scanning. It works as follows. During the key press (which takes relatively long) the ISR will sequentially make each column low (the others high) and then checks for a low on the rows. Only the row and column with the pressed key will conduct a low to the corresponding row. Since it is known which column is low at that time, the key can be determined.
For each key an unique code is set up. This code (8 bit with start and stop bit) is send serially to the IR LED. It is common in IR applications to modulate the data with a 38kHz signal to avoid EMC interference. In this transmitter, a high is send as a 38kHz signal, a low as a low. In fact the data is ANDed with the modulator. The duty cycle for this IR signal is set to 50% and the pulse length is 1ms. Then, the transmitted frequency is around 1kHz which is handled well by most IR LEDs.
In itself the receiver does the opposite of the transmitter; it decodes the data and updates the main MCU program. A valid signal is received and synchronised using the "positive edge trigger" interrupt of the controller. The start bit creates this positive edge. The received 8 bits are compared to the unique values and the associated ports are updated. If no match is found, the data is ignored.