Hiro's Home Page
Making Electric Volume - Software Design
(Feb. 28 2010)
Index
Task Management
Task Manipulation Interface Functions
There are five functions that manipulate tasks;
task_register() function registers a task with a specified priority. The priority defines how often the task gets actual execution time.
task_suspend() suspends a task. Suspended tasks never get execution time until they are resumed, by task_resume(), or activated, by task_active().
task_active() activates a task. Tasks activated by the function fall into ACTIVE state and get execution time as soon as possible.
task_resume() reschedules execution timing for a task taking the task priority, which is set by task_register(), into account.
task_sleep() sets a task SLEEPING status. Sleeping time duration can be specified in mili-seconds.
Task Switching and Task Priority
Actual task switching is made in the main() function. The switching timing is triggered by TIMER0 interrupt, which is set 2 mili-seconds. The next execution timing for a task is set by task_resume() function or just after the execution of the task in task switching routine, the main() function. The next execution timing for a task with priority p is defines as
T = (p + 1) * t
where t is the task switching interval, 2 mili-seconds.
TIMER1 Interface
TIMER1 is used as a free incremental counter for time interval measurement. There are two interface functions, timer1_get_4usec() and timer1_get_1msec().
timer1_get_4usec() returns a counter value measured in 4 μ seconds.
timer1_get_1msec() returns a counter value measured in 1 mili-seconds.
LM1973 Attenuation Control
There are eight functions for attenuation control.
volume_set_volume() sets attenuation. The attenuation level, A dB, and the volume level passed to volume_set_volume(), V, is related as
A = -0.5 * (50 - V)
where the volume level, V, can take 0 - 50.
volume_get_volume() returns current volume level.
volume_get_atten() returns current attenuation level. Note that the returned value is opposite signed value of actual attenuation level.
volume_up() increments volume level.
volume_down() decrements volume level.
volume_mute() mutes LM1973 output.
volume_unmute() unmutes LM1973 output.
volume_ckeck_mute() returns the status of LM1973; 0 is unmuted status and 1 is muted status.
EEPROM Interface
There are six functions to read and write EEPROM.
eeprom_read8() reads 1 byte data from the specified EEPROM address.
eeprom_read16() reads 2 byte data from the specified EEPROM address.
eeprom_read32() reads 4 byte data from the specified EEPROM address.
eeprom_write8() writes 1 byte data to the specified EEPROM address.
eeprom_write16() writes 2 byte data to the specified EEPROM address.
eeprom_write32() writes 4 byte data to the specified EEPROM address.
Seven Segment
Seven Segment control is achieved by a management task and three interface functions.
Seven Segment Management Task
The management task, task_sevensegment(), takes the roll of illuminating LED's. The task's priority is set the highest, '0', in the system (refer to "electricvolume.h").
Seven Segment has three display status: MUTE, NORMAL and BLINK. In the MUTE status Seven Segment blacks out. Seven Segment displays a two digit value normally in NORMAL status. In BLINK status, Seven Segment displays two digit value with blinking.
Seven Segment Interface Functions
ss_display_dec() displays a two digit decimal value. The value can take 0 to 99.
ss_display_hex() displays a two digit hexadecimal value. The value can take 0x00 to 0xFF.
ss_display_char() displays a two digit characters set associated to a specified value. The character sets are defined as
| VALUE | CHARACTER SET | COMMENT |
|---|---|---|
| 0 | OF | OFF |
| 1 | On | ON |
| 2 | uP | UP |
| 3 | dn | DOWN |
| 4 | == | MUTE |
| 5 | P1 | PRESET 1 |
| 6 | P2 | PRESET 2 |
| 7 | P3 | PRESET 3 |
| 8 | P4 | PRESET 4 |
| 9 | P5 | PRESET 5 |
Rotary Encoder
The Rotary encoder is controlled by a management task, task_rotaryencoder().
The management task
IR Sensor
IR sensor control consists of a interrupt routine, a management task and four interface functions.
IR Interrupt Routine
The signal from the IR sensor, PL-IRM0101-3, is fed to RB7 pin of PIC16F88 and PORTB change interrupt is used to detect the change of IR signal. The IR interrupt routine checks ON=>OFF and OFF=>ON signal transition and
IR Management Task
The management task, task_infrared(), wakes up every 150 mili-seconds normally and controls volume level of LM1973 according to the received IR code. Because the system can learn which volume control function (UP, DOWN, MUTE or PRESET 1-5) is associated to an IR code, the management task simply compares 32 bit data and execute the associated function.
IR Interface Functions
ir_code_init() reads IR codes for volume control functions (UP, DOWN, MUTE and PRESET 1-5) from EEPROM.
ir_get_last_code() returns the 32 bit IR code received most recently.
ir_set_code() makes the association of a volume control function and a 32 bit IR code. The function saves the association information to EEPROM as well.
ir_set_preset() makes the association of a preset function and preset information (a 32 bit IR code and a volume level). The function saves the association information to EEPROM as well.
Push Button
Push button is controlled by a management task, task_pushbutton().
The management task controls two system status: NORMAL MODE and LEARNING MODE. When the system is in NORMAL MODE, the management task simply keeps watching the button status, waking up every 100 mili-seconds, and makes the system LEARNING MODE when the button is kept down (ON) for more than 3 seconds.
When the system is going into LEARNING MODE, the management task suspends IR management task.
In the LEARNING MODE, the management task
The system learns IR codes in a order of UP => DOWN => MUTE => PRESET 1 => .... => PRESET 5 functions. The volume control functions (UP, DOWN, MUTE and PRESET 1-5) to learn transits one by one as the button is pushed down.
Since the management task takes the latest IR code received when learning an IR code, you can enter IR key pad multiple times before pushing the button.
For PRESET 1-5 functions, a volume level is read and saved with an IR code. Volume level can be varied by turning the rotary encoder.
When returning to NORMAL MODE after finishing learning IR codes, the management task resumes IR management task.