2023-12-09 17:27:53 +00:00
|
|
|
# AVR ATiny13 Project 002
|
2023-12-09 17:00:30 +00:00
|
|
|
|
2023-12-09 17:27:53 +00:00
|
|
|
This is the firmware for a latching dual relay system. It allows the user to
|
2024-01-04 01:43:15 +00:00
|
|
|
switch two DPDT relays by with two separate switches.
|
2023-12-09 17:27:53 +00:00
|
|
|
|
|
|
|
|
2024-01-04 01:43:15 +00:00
|
|
|
## Components:
|
2023-12-09 17:27:53 +00:00
|
|
|
|
|
|
|
**Micro:** AVR ATiny13, ATiny25/45/85
|
|
|
|
|
|
|
|
## Instructions:
|
|
|
|
|
|
|
|
1. Power the system using a 1.8v~5.5v power supply
|
|
|
|
2. Set/program the AVR to use a 1MHz clock rate.
|
|
|
|
3. Connect the pins as described above.
|
|
|
|
|
|
|
|
**ACTIVATING RELAYS:**
|
|
|
|
|
|
|
|
1. Activate the desired button with a quick press <= 350ms.
|
|
|
|
2. Repeat to toggle the relay.
|
|
|
|
|
|
|
|
**TEMPORARY TOGGLE:**
|
|
|
|
|
|
|
|
1. Press and hold the desired button >= 350ms.
|
|
|
|
2. Let go to disable.
|
|
|
|
|
|
|
|
**SAVING SETTINGS:**
|
|
|
|
|
|
|
|
1. Press and hold the target button.
|
|
|
|
2. While holding the button power cycle the device.
|
2024-01-04 01:43:15 +00:00
|
|
|
3. When the setting is successfully saved the relay/led will blink/toggle.
|
2023-12-09 17:27:53 +00:00
|
|
|
4. repeat until desired preset is saved.
|
|
|
|
|
|
|
|
|
|
|
|
## Technical Aspects:
|
|
|
|
|
|
|
|
The use of C style bitfields has been used inside a struct to maintain a global
|
|
|
|
state. It minimizes the size of the binary once compiled.
|
|
|
|
|
|
|
|
The majority of the code is blocking/polling; overhead from introducing
|
|
|
|
interrupts and ISR(interrupt service routines) wasn't as clean and made it more
|
|
|
|
platform dependent.
|
|
|
|
|
|
|
|
The code right now can for the most part be ported to any AVR micro-controller
|
|
|
|
with no changes.
|
|
|
|
|
2024-01-04 01:39:51 +00:00
|
|
|
## Timings
|
|
|
|
|
|
|
|
The current setup is calculated for a attiny13/a running at 4.8Mhz without the
|
2024-01-04 01:43:15 +00:00
|
|
|
clock divider fuse set.
|
2024-01-04 01:39:51 +00:00
|
|
|
|
|
|
|
This means that the actual f_cpu is 4.8Mhz to calculate the delay times
|
|
|
|
we can use this formula:
|
|
|
|
|
|
|
|
$$
|
2024-01-04 01:44:29 +00:00
|
|
|
msPerOverflow = 1000ms / (\frac{4.8Mhz}{64} * \frac{1}{256}) \approx 6.8ms
|
2024-01-04 01:39:51 +00:00
|
|
|
$$
|
|
|
|
|
2024-01-04 01:43:15 +00:00
|
|
|
Where $64$ is the pre scaler setting and $256$ is the maximum value of the 8bit
|
|
|
|
timer.
|
2023-12-09 17:27:53 +00:00
|
|
|
|
|
|
|
## BUILDING PROJECT:
|
|
|
|
|
|
|
|
|
|
|
|
**On Unix**
|
|
|
|
```sh
|
|
|
|
git clone <REPOURL>
|
|
|
|
cd <REPO>
|
|
|
|
make flash
|
|
|
|
```
|
|
|
|
|
|
|
|
## Flashing the Project
|
|
|
|
|
2024-01-04 01:35:36 +00:00
|
|
|
**On Windows(usbtinyisp)**
|
2023-12-09 17:27:53 +00:00
|
|
|
|
2024-01-04 01:35:36 +00:00
|
|
|
1. Install the usbtiny driver:
|
|
|
|
1. plug in usbtiny device
|
2024-01-04 01:43:15 +00:00
|
|
|
2. Install the drivers from: [adafruit](https://learn.adafruit.com/usbtinyisp/drivers)
|
|
|
|
2. open Powershell
|
2023-12-09 17:27:53 +00:00
|
|
|
3. navigate to the repo directory *cd Downloads\gf_002*
|
|
|
|
4. enter the command below.
|
|
|
|
|
|
|
|
```ps1
|
2024-01-04 01:35:36 +00:00
|
|
|
./avrdude.exe -p t13 -c usbtiny -B 125kHz -U flash:w:.\pre_built\attiny13_4-8Mhz.hex -U lfuse:w:0x79:m -U hfuse:w:0xFF:m -U lock:w:0xFF:m
|
2023-12-09 17:27:53 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
|
2024-01-04 01:35:36 +00:00
|
|
|
**On Windows(usbASP)**
|
|
|
|
|
|
|
|
1. Install the usbasp driver:
|
|
|
|
1. plug in usbasp device
|
|
|
|
2. run the 'zadig-2.8.exe' program
|
|
|
|
3. select the libusb 32 on the right by clicking the down arrow to select.
|
2024-01-04 01:43:15 +00:00
|
|
|
2. open Powershell
|
2024-01-04 01:35:36 +00:00
|
|
|
3. navigate to the repo directory *cd Downloads\gf_002*
|
|
|
|
4. enter the command below.
|
2023-12-09 17:27:53 +00:00
|
|
|
|
2024-01-04 01:35:36 +00:00
|
|
|
```ps1
|
|
|
|
./avrdude.exe -p t13 -c usbasp -B 125kHz -U flash:w:.\pre_built\attiny13_4-8Mhz.hex -U lfuse:w:0x79:m -U hfuse:w:0xFF:m -U lock:w:0xFF:m
|
|
|
|
```
|
2023-12-09 17:27:53 +00:00
|
|
|
|