Introduction
This project was designed using KiCad. If you wish to examine the design yourself the project is available for download below. The main circuitry is on the DERCOASTER-CONTROL PCB which is what we’ll review below. Datasheets for each IC are linked at the end of this page. The shipping PCB versions are DERCOASTER-04 and DERCOASTER-CONTROL-06.
Terminology
Term | Description |
---|---|
Ground (Vss) | All voltages in the circuit are referenced from this point and by definition its voltage is 0V |
Supply voltage (VCC) | The supply voltage generated for providing power to the circuitry. It’s called VCC for historical reasons which references the bi-polar transistor collector connection. |
Low Signal | The voltage of the signal or pin is near ground |
High Signal | The voltage of the signal or pin is near VCC |
Active Low | The signal is inverted and activates a function when it’s low |
Pull-down resistor | A resistor connected between the signal and ground to keep it low when not connected or driven by anything else |
Pull-up resistor | A resistor connected between the signal and supply (VCC) to keep it high when not connected or driven by anything else |
GPIO | General purpose Input/Output |
Falling edge | Signal change from high to low |
Rising edge | Signal change from low to high |
Microcontroller
The ATtiny44A is an 8-bit AVR microcontroller capable of 20 MHz operating frequency with 8 kilobytes of RAM and 4 kilobytes of flash storage. It comes in a 14-pin SOIC package and can operate with a supply voltage between 1.8 to 5.5 V. In this circuit we’ve chosen a supply voltage of 5V which is directly available from the USB connector which eliminates the need for a voltage regulator. It is also the supply voltage needed for the addressable RGB LEDs. The additional characters trailing the full part number “SSU” from “ATTINY44A SSU” details the pin count, package type, and temperature rating. In this case the first two characters “SS” means SOIC-14 package, “U” means –40 to 85 °C operating temperature. For more details on decoding the part number see page 277 in the microcontroller datasheet.
Power pin decoupling
Normally each supply pin should have one small capacitor placed near it for high-frequency noise decoupling. A value of 100 nF (0.1 uF) is common due to low cost and sufficient capacity. This specific microcontroller only has a single VCC supply pin and in order to reduce the component count we place our bulk capacitor (4.7 uF) near this pin instead of using a separate decoupling capacitor.
RESETn
The after RESET indicates the signal is active low. This means when this pin is grounded (near 0V) it will activate the reset signal inside the microcontroller and keep it in that state until the signal is changed to high state (near VCC). There’s an internal pull-up resistor to VCC inside the microcontroller which keeps this signal inactive when not connected to anything. We’ve added a 10 nF capacitor (C2) and a 10 kΩ pull-up resistor (R1 to the pin to prevent it from glitching (unintended activation). You can test this effect first by not adding this capacitor and touching the RESET pin (#4) with your finger while the microcontroller is operating to see what happens.
GPIO
In order to evaluate where we want to connect our signals to pins of the microcontroller we have to know which peripheral (internal hardware function) can be used on which pin. The microcontroller datasheet shows us the pinout on page 8. In our case we need one input pin for our button (BUTTONn) and one output pin for sending data to the LEDs (LED_DIN). To simplify detection of button presses we want to connect the button to an input pin with external interrupt functionality. This means we can automatically run code when a button press is detected without having to constantly check the pin state. We’ve chosen to use pin 10 (PA3) for this and the PCINT3 function (Pin Change Interrupt 3). We don’t require any specific microcontroller function to send data to the LEDs, we just need an output pin which we can change the state of. We’ve chosen pin 5 (PB2) in our circuit as the location was conveninent.
Debug pins
AVR microcontrollers support the programming over serial peripheral interface (SPI). This specific project has the firmware already programmed to the microcontroller and does not need to be programmed. There is however the possibility of exploring this project further yourself by attaching a programmer to the board and uploading your own firmware. For this reason we’ve routed the relevant debug pins to the J1 header. We recommend the USBasp programmer which is widely available in different versions at a low price. For example it’s available for 7 EUR on Amazon Germany or for 1.8 USD on Aliexpress.
RGB LED
The RGB LED we’ve chosen for our circuit is the well known WS2812B from World Semi. It supports a custom single-wire data interface which lets you daisy-chain any number of LED ICs and provides fully digital control of the RGB values. There are 8 LEDs connected in series on the DERCOASTER-CONTROL PCB and an additional 12 LEDs following the same chain on the DERCOASTER PCB. Details on how the interface works is available in the WS2812B datasheet page 4. Version 5 of this IC does not require any decouple capacitor, further reducing our component count.
USB-C Connector
This project relies on the 5 V supplied directly from the USB-C connector to power the microcontroller and LEDs. A slide switch (SW1) lets you connect or remove power to the board. A ferrite bead (FB1) and large 4.7 uF capacitor (C1) forms an input power supply filter to prevent large transients when connecting the USB cable or flipping the power power switch. We’re not using the data functionality of the USB-C interface and most of the pins are not connected. The USB CC lines is a new addition with the USB-C connector which is used for negotiating the type of device and its power requirements. We’re using a simple implementation with a 5.1 kΩ resistor connected between CC1/CC2 and ground. This indicates that this devices needs a supply voltage of 5 V and can draw least 1.5 A and up to 3.0 A of current.
Button
To detect when the button has been pressed we can simply configure it as an input and continuously read its state in our code. But unless this is the only task we have to perform, it would be possible to miss a button press when performing other tasks. Not to mention it would waste clock cycles. A better way is to configure an external interrupt to occur whenever the pin state is changed. This is a another peripheral available in the microcontroller which jumps to a certain place in your code when a condition has been detected without us having to continuously monitor it. We’ve decided to use PCINT3 on PA3 for BUTTONn because that pin was in a suitable location for making the physical connection to the push button switch. One side of the button switch is attached to ground (0 V) and the other end connects to the microcontroller pin through a 100 Ω resistor with a 10 nF capacitor forming a low pass filter to limit noise. Additionally a 10 kΩ pull-up resistor to 5 V is added to set the voltage on the pin when the button is not pressed. This results in a default state with 5 V (logic high) on the pin when not pressed and 0 V (logic low) on the pin when the button is pressed. This means we set the external interrupt to detect a falling edge condition (signal change from high to low).
Pin headers
The four pin headers (J1-J4) on the DERCOASTER-CONTROL PCB align with the matching pin sockets on the DERCOASTER PCB to form the mechanical and electrical connection between the two PCBs. This allows us to connect power only to the control PCB and transfer it to the coaster PCB using these pins. It also lets us send the digital LED control signal to the second PCB to also control those LEDs. We’ve added 100 Ω resistors in series for each signal improve noise immunity and limit the current on any pin if they’re accidentally connected to something they shouldn’t.
References
- Microchip ATtiny44A Datasheet (general overview, register definitions, electrical specification)
- World Semi WS2812B-B/W
- Introduction to USB Type-C (Microchip AN1953)