User Tools

Site Tools


projects:advent

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
projects:advent [2016-02-01 17:21]
robert created
projects:advent [2016-02-10 17:14]
robert [Function]
Line 35: Line 35:
  
 As always, there are a few complications:​ As always, there are a few complications:​
-  * In order to prevent a "​ripping the advent calendar open and eating all the chocolate at once" incident (i.e. turning on LEDs early), the calendar keeps track of the time between ​button ​pressesOnly if there are more than 10 hours since the last button press, a new LED will come on. That time interval was chosen to account for the possibility of the button being pressed ​at any point during the working day (e.g. 17:00 on one day, and 07:00 on the next).  +  * In order to prevent a "​ripping the advent calendar open and eating all the chocolate at once" incident (i.e. turning on LEDs early), the calendar keeps track of the time elapsed sine the button ​has last been pushednew LED will only come on if the last successful push of the button was more than 10 hours ago. That time interval was chosen to account for the possibility of the button being pushed ​at any point during the working day (e.g. 17:00 on one day, and 07:00 on the next).  
-  * However, after weekends or days off it should be possible to catch up on the missed days without the 10-hour interval. For example, it should be possible to press the button thrice in a row for three LEDs to come on on a Monday morning - once for Saturday, once for Sunday, and once for Monday. In order to make this possible, LEDs can be lit successively ​if the previous button ​press is more than 24 hours in the past. In effect, every 24 hours since the time the button was last pressed ​allow an LED to come on without the 10-hour lockout time.+  * However, after weekends or days off it should be possible to catch up on the missed days without the 10-hour interval. For example, it should be possible to push the button thrice in a row for three LEDs to come on on a Monday morning - once for Saturday, once for Sunday, and once for Monday. In order to make this possible, ​several ​LEDs can be lit in succession ​if the previous ​push of the button is more than 24 hours in the past. In effect, every 24 hours since the time the button was last pushed ​allow an LED to come on without the 10-hour lockout time.
   * The current state of the advent calendar is stored in the mbed's flash memory, and is accessible through the file system. This is great for debugging and makes the firmware quite a bit simpler, but it does have the unfortunate side effect that pranksters can tamper with the files. Luckily, a "​feature"​ of the mbed's file system implementation means that it [[https://​developer.mbed.org/​handbook/​LocalFileSystem|won'​t show up as a USB mass storage device if there are any open file handles]]. In the case of tamper-proofing the advent calendar this can be used as an advantage - simply open a dummy file and keep it open, and it won't show up on the computer. This appeared to be enough of a hurdle to put an end to the mischievous deeds of the chief office prankster.   * The current state of the advent calendar is stored in the mbed's flash memory, and is accessible through the file system. This is great for debugging and makes the firmware quite a bit simpler, but it does have the unfortunate side effect that pranksters can tamper with the files. Luckily, a "​feature"​ of the mbed's file system implementation means that it [[https://​developer.mbed.org/​handbook/​LocalFileSystem|won'​t show up as a USB mass storage device if there are any open file handles]]. In the case of tamper-proofing the advent calendar this can be used as an advantage - simply open a dummy file and keep it open, and it won't show up on the computer. This appeared to be enough of a hurdle to put an end to the mischievous deeds of the chief office prankster.
  
 ====Circuit==== ====Circuit====
-Coming soon.+The circuit used is embarrassingly simple: Each LED is powered from the USB supply, driven by a ULN2003, and has its current limited by a trimmpotThere is one GPIO pin for each LED, so no fancy multiplexing or anything clever.  
 + 
 + 
 +{{ :​projects:​advent-driver.png?​direct&​400 |}} 
 +<WRAP centeralign>​ 
 +//LED driver schematic. There are 24 of these.// 
 +</​WRAP>​ 
 + 
 +There are a few reasons why this rather inelegant and simple driving method was chosen: 
 +  * Despite the large number of components, it was actually fairly quick to build 
 +  * Having one trimmer per LED allows to set the current reasonably accurately to balance brightness 
 +  * Without multiplexing,​ the LEDs can be easily driven with a PWM waveform. 
 + 
 +The resistor values for the trimmers were calculated beforehand to get a rough idea of the values required to equalise the perceived brightness of all LEDs. However, as one would imagine, there was quite a bit of tweaking involved in the end to get everything looking just right - and unfortunately I ran out of trimmers of the same style and had to resort to a few even crustier ones from my box. 
 + 
 +Apart from that, literally the only other components on the board are a pushbutton switch with a pull-up resistor and a CR2032 for the battery-backed RTC of the mbed.  
 + 
 + 
 +{{ :​projects:​advent-rest.png?​direct&​400 |}} 
 +<WRAP centeralign>​ 
 +//​Boring.//​ 
 +</​WRAP>​
  
 {{ :​projects:​advent-overview.jpg?​direct&​400 |}} {{ :​projects:​advent-overview.jpg?​direct&​400 |}}
Line 49: Line 70:
  
 ====Firmware==== ====Firmware====
-Coming ​soon.+Like the hardware, the firmware is really quite simple - It primarily consists of a state machine that deals with the switch input and turns on LEDs accordingly. The current number of LEDs that are on, and the sequence in which the LEDs turn on are kept in files on the mbed's embedded flash (accessible through the mass storage device).  
 + 
 +One of the very few aspects of note about the firmware is the bit-bang PWM: When an LED turns on, it fades in slowly over a second or so. Since the mbed doesn'​t have 24 PWM channels and the LEDs aren't multiplexed,​ I had to implement a software PWM generator. This will works on any one pin at a time and is reasonably accurate and stable because the state machine is clocked and the time taken to execute it is fairly constant. The fade-in of the LEDs follows a quadratic duty cycle in order to get a perceived linear (well, close enough) fading effect. Again, thanks to the computing power provided by the mbed this task did not even pose a remote challenge. 
 + 
 +<WRAP center round info 60%> 
 +Github repo coming ​soon. 
 +</​WRAP>​ 
projects/advent.txt · Last modified: 2016-02-10 17:14 by robert