Commit 8c053034 authored by Thomas Maaß's avatar Thomas Maaß
Browse files

Initial commit

parents
# **Cabinet-Power-Switch PCB**
## Summary
The PCB was created with Kicad.
It is used to switch the main voltage in an arcade cabinet or similar.
The poweron is triggered by a pushbutton. The poweroff is triggered, when the 5 V at the PC5V input shuts down.
Connect this for example to the 5 V HDD power connector.
Because of the optocoupler, there is an isolation between PC5V and the maincircuit.
The main supply voltage Ub can be 6.5 - 36 V.
The output can either pulse or switch a relay. The behaviour can be changed in the code.
## Compiling
Install avr-gcc and type a simple "make" to compile.
## Programming
You can program the ATtiny with every AVR compatible ISP-programmer.
Install avrdude. Edit the programmer options in the Makefile, then type "make install" to flash.
![cabinet-power-switch-top](kicad/cabinet-power-switch-top.png)
![cabinet-power-switch-bottom](kicad/cabinet-power-switch-bottom.png)
# Makefile for AVR MCUs
TARGET = main
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
NM = avr-nm
SIZE = avr-size
MCU = attiny85
F_CPU = 1000000UL
FORMAT = ihex
PROGRAMMER = atmelice_isp
PORT = usb
AVRDUDE = avrdude
AVRDUDE += -c $(PROGRAMMER)
AVRDUDE += -p $(MCU)
AVRDUDE += -P $(PORT)
FUSES = -U lfuse:w:0x62:m
FUSES += -U hfuse:w:0xdf:m
FUSES += -U efuse:w:0xff:m
CFLAGS = -gdwarf-2
CFLAGS += -Os
CFLAGS += -funsigned-char
CFLAGS += -funsigned-bitfields
CFLAGS += -fpack-struct
CFLAGS += -fshort-enums
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
CFLAGS += -Wall
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
CFLAGS += -std=gnu99
CFLAGS += -mmcu=$(MCU)
CFLAGS += -DF_CPU=$(F_CPU)
CFLAGS += -DAVR_USE_HW_SPI
CFLAGS += -DSCK_DDR=DDRB
CFLAGS += -DSCK_BIT=5
CFLAGS += -DMOSI_DDR=DDRB
CFLAGS += -DMOSI_BIT=3
CFLAGS += -I.
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
ASFLAGS += -DF_CPU=$(F_CPU)
ASFLAGS += -mmcu=$(MCU)
ASFLAGS += -x assembler-with-cpp
ASFLAGS += -I.
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref,--gc-sections
LDFLAGS += -lm
LDFLAGS += -mmcu=$(MCU)
SRC = $(shell ls *.c)
ASRC =
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
all: elf hex eep lss sym
elf: $(TARGET).elf
hex: $(TARGET).hex
eep: $(TARGET).eep
lss: $(TARGET).lss
sym: $(TARGET).sym
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
$(CC) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
%.hex: %.elf
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
%.eep: %.elf
$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
%.lss: %.elf
$(OBJDUMP) -h -S $< > $@
%.sym: %.elf
$(NM) -n $< > $@
%.o : %.c
$(CC) -c $(CFLAGS) $< -o $@
%.o : %.S
$(CC) -c $(ASFLAGS) $< -o $@
%.s : %.c
$(CC) -S $(CFLAGS) $< -o $@
size: main.elf
$(SIZE) --mcu=$(MCU) --format=avr main.elf
clean:
rm -f \
$(OBJ) \
$(TARGET).hex \
$(TARGET).eep \
$(TARGET).obj \
$(TARGET).cof \
$(TARGET).elf \
$(TARGET).map \
$(TARGET).obj \
$(TARGET).a90 \
$(TARGET).sym \
$(TARGET).lnk \
$(TARGET).lss \
$(OBJ) \
$(LST) \
$(SRC:.c=.s) \
$(SRC:.c=.d)
rm -Rf .dep
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
install: program fuse
program:
$(AVRDUDE) -U flash:w:$(TARGET).hex -U eeprom:w:$(TARGET).eep
fuse:
$(AVRDUDE) $(FUSES)
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
#define OUTPUT 0 // Behaviour of output - 0 = Pulse, 1 = Switch
uint8_t State;
void initPorts() {
DDRB = 0x01;
PORTB = 0x3e;
}
void initInterrrupts() {
GIMSK |= (1 << INT0);
MCUCR |= ((1 << ISC00) | (1 << ISC01));
GIMSK |= (1 << PCIE);
PCMSK |= (1 << PCINT1);
sei();
return;
}
void initPowersave() {
ADCSRA |= (0 << ADEN);
PRR |= (1 << PRADC) | (1 << PRTIM0) | (1 << PRTIM1) | (1 << PRUSI);
ACSR |= (1 << ACD);
set_sleep_mode(SLEEP_MODE_IDLE);
sleep_enable();
}
void debounce(volatile uint8_t *port, uint8_t mask) {
uint8_t port_buffer;
uint8_t debounce_buffer;
for (debounce_buffer = 0; debounce_buffer != 0xff;) {
debounce_buffer <<= 1;
port_buffer = *port;
_delay_us(15);
if ((*port & mask) == (port_buffer & mask)) {
debounce_buffer |= 0x01;
}
}
}
void setState() {
_delay_ms(3000);
if (PINB & (1 << PINB2)) {
State = 0;
}
else {
State = 1;
}
return;
}
void pulseRelais() {
PORTB |= (1 << PB0);
_delay_ms(100);
PORTB &= ~(1 << PB0);
return;
}
void toggleRelais() {
if (State) {
PORTB &= ~(1 << PB0);
}
else {
PORTB |= (1 << PB0);
}
return;
}
int main(void) {
//PB0 = output, PB1 = Switch, PB2 = PC 5V
initPorts();
initInterrrupts();
initPowersave();
setState();
while (1) {
sleep_mode();
}
return 0;
}
ISR(INT0_vect) {
if (State) {
#if OUTPUT == 0
pulseRelais();
#elif OUTPUT == 1
toggleRelais();
#endif
setState();
}
return;
}
ISR(PCINT0_vect) {
debounce(&PINB, (1 << PINB1));
if (!(PINB & (1 << PINB1))) {
if (!State) {
#if OUTPUT == 0
pulseRelais();
#elif OUTPUT == 1
toggleRelais();
#endif
}
setState();
}
return;
}
This diff is collapsed.
{
"board": {
"active_layer": 31,
"active_layer_preset": "All Layers",
"auto_track_width": true,
"hidden_nets": [],
"high_contrast_mode": 0,
"net_color_mode": 1,
"opacity": {
"pads": 1.0,
"tracks": 1.0,
"vias": 1.0,
"zones": 0.6
},
"ratsnest_display_mode": 0,
"selection_filter": {
"dimensions": true,
"footprints": true,
"graphics": true,
"keepouts": true,
"lockedItems": true,
"otherItems": true,
"pads": true,
"text": true,
"tracks": true,
"vias": true,
"zones": true
},
"visible_items": [
0,
1,
2,
3,
4,
5,
6,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
32,
33,
34,
35,
36
],
"visible_layers": "fffffff_ffffffff",
"zone_display_mode": 0
},
"meta": {
"filename": "cabinet-power-switch.kicad_prl",
"version": 3
},
"project": {
"files": []
}
}
{
"board": {
"design_settings": {
"defaults": {
"board_outline_line_width": 0.049999999999999996,
"copper_line_width": 0.19999999999999998,
"copper_text_italic": false,
"copper_text_size_h": 1.5,
"copper_text_size_v": 1.5,
"copper_text_thickness": 0.3,
"copper_text_upright": false,
"courtyard_line_width": 0.049999999999999996,
"dimension_precision": 4,
"dimension_units": 3,
"dimensions": {
"arrow_length": 1270000,
"extension_offset": 500000,
"keep_text_aligned": true,
"suppress_zeroes": false,
"text_position": 0,
"units_format": 1
},
"fab_line_width": 0.09999999999999999,
"fab_text_italic": false,
"fab_text_size_h": 1.0,
"fab_text_size_v": 1.0,
"fab_text_thickness": 0.15,
"fab_text_upright": false,
"other_line_width": 0.09999999999999999,
"other_text_italic": false,
"other_text_size_h": 1.0,
"other_text_size_v": 1.0,
"other_text_thickness": 0.15,
"other_text_upright": false,
"pads": {
"drill": 0.762,
"height": 1.524,
"width": 1.524
},
"silk_line_width": 0.12,
"silk_text_italic": false,
"silk_text_size_h": 1.0,
"silk_text_size_v": 1.0,
"silk_text_thickness": 0.15,
"silk_text_upright": false,
"zones": {
"45_degree_only": false,
"min_clearance": 0.508
}
},
"diff_pair_dimensions": [
{
"gap": 0.0,
"via_gap": 0.0,
"width": 0.0
}
],
"drc_exclusions": [],
"meta": {
"filename": "board_design_settings.json",
"version": 2
},
"rule_severities": {
"annular_width": "error",
"clearance": "error",
"copper_edge_clearance": "error",
"courtyards_overlap": "error",
"diff_pair_gap_out_of_range": "error",
"diff_pair_uncoupled_length_too_long": "error",
"drill_out_of_range": "error",
"duplicate_footprints": "warning",
"extra_footprint": "warning",
"hole_clearance": "error",
"hole_near_hole": "error",
"invalid_outline": "error",
"item_on_disabled_layer": "error",
"items_not_allowed": "error",
"length_out_of_range": "error",
"malformed_courtyard": "error",
"microvia_drill_out_of_range": "error",
"missing_courtyard": "ignore",
"missing_footprint": "warning",
"net_conflict": "warning",
"npth_inside_courtyard": "ignore",
"padstack": "error",
"pth_inside_courtyard": "ignore",
"shorting_items": "error",
"silk_over_copper": "warning",
"silk_overlap": "warning",
"skew_out_of_range": "error",
"too_many_vias": "error",
"track_dangling": "warning",
"track_width": "error",
"tracks_crossing": "error",
"unconnected_items": "error",
"unresolved_variable": "error",
"via_dangling": "warning",
"zone_has_empty_net": "error",
"zones_intersect": "error"
},
"rules": {
"allow_blind_buried_vias": false,
"allow_microvias": false,
"max_error": 0.005,
"min_clearance": 0.0,
"min_copper_edge_clearance": 0.024999999999999998,
"min_hole_clearance": 0.0,
"min_hole_to_hole": 0.25,
"min_microvia_diameter": 0.19999999999999998,
"min_microvia_drill": 0.09999999999999999,
"min_silk_clearance": 0.0,
"min_through_hole_diameter": 0.3,
"min_track_width": 0.19999999999999998,
"min_via_annular_width": 0.049999999999999996,
"min_via_diameter": 0.39999999999999997,
"use_height_for_length_calcs": true
},
"track_widths": [
0.0,
1.0,
2.0
],
"via_dimensions": [
{
"diameter": 0.0,
"drill": 0.0
}
],
"zones_allow_external_fillets": false,
"zones_use_no_outline": true
},
"layer_presets": []
},
"boards": [],
"cvpcb": {
"equivalence_files": []
},
"erc": {
"erc_exclusions": [],
"meta": {
"version": 0
},
"pin_map": [
[
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
2,
0,
1,
0,
0,
1,
0,
2,
2,
2,
2
],
[
0,
0,
0,
0,
0,
0,
1,
0,
1,
0,
1,
2
],
[
0,
1,
0,
0,
0,
0,
1,
1,
2,
1,
1,
2
],
[
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
2
],
[
1,
1,
1,
1,
1,
0,
1,
1,
1,
1,
1,
2
],
[
0,
0,
0,
1,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
2,
1,
2,
0,
0,
1,
0,
2,
2,
2,
2
],
[
0,
2,
0,
1,
0,
0,
1,
0,
2,
0,
0,
2
],
[
0,
2,
1,
1,
0,
0,
1,
0,
2,
0,
0,
2