From ed24a7090a6cae59e1f877e61c20e62fda31ed4a Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sun, 3 Jan 2021 17:16:50 +0200 Subject: [PATCH] started on the firmware, added BOM --- .gitignore | 9 + fw/Makefile | 41 ++ fw/src/main.c | 98 ++++ fw/src/serial.c | 103 +++++ fw/src/serial.h | 7 + hw/bom.ods | 1300 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/nixiedisp.sch | 69 +-- 7 files changed, 1601 insertions(+), 26 deletions(-) create mode 100644 fw/Makefile create mode 100644 fw/src/main.c create mode 100644 fw/src/serial.c create mode 100644 fw/src/serial.h create mode 100644 hw/bom.ods diff --git a/.gitignore b/.gitignore index bc7276b..40827ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,14 @@ +*.o +*.d *.swp *.*-bak _autosave-* *.bck *.net +*.pdf +*.jpg +*.zip +*.eep +*.hex +*.map +fw/nixiedisp diff --git a/fw/Makefile b/fw/Makefile new file mode 100644 index 0000000..6e295ac --- /dev/null +++ b/fw/Makefile @@ -0,0 +1,41 @@ +src = $(wildcard src/*.c) +obj = $(src:.c=.o) +bin = nixiedisp +hex = $(bin).hex +eep = $(bin).eep + +mcu_gcc = atmega328p +mcu_dude = m328p + +CC = avr-gcc +OBJCOPY = avr-objcopy + +CFLAGS = -Os -pedantic -Wall -mmcu=$(mcu_gcc) -DF_CPU=14745600 +LDFLAGS = -Wl,-Map,$(bin).map -mmcu=$(mcu_gcc) -lprintf_min + +.PHONY: all +all: $(hex) $(eep) + +$(bin): $(obj) + $(CC) -o $@ $(obj) $(LDFLAGS) + +$(hex): $(bin) + $(OBJCOPY) -j .text -j .data -O ihex -R .eeprom $< $@ + +$(bin).bin: $(bin) + $(OBJCOPY) -j .text -j .data -O binary -R .eeprom $< $@ + +$(eep): $(bin) + $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ + +.PHONY: fuses +fuses: + avrdude -c usbtiny -p $(mcu_dude) -U lfuse:w:0xe6:m -U hfuse:w:0xdf:m -U efuse:w:0xf9:m + +.PHONY: program +program: $(hex) + avrdude -c usbtiny -p $(mcu_dude) -e -U flash:w:$(hex) + +.PHONY: clean +clean: + rm -f $(bin) $(obj) $(hex) $(eep) $(bin).map diff --git a/fw/src/main.c b/fw/src/main.c new file mode 100644 index 0000000..3c1bd55 --- /dev/null +++ b/fw/src/main.c @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#include +#include +#include "serial.h" + +/* TODO before board arrive: + * - USB comms + * - RTC time/data setting + * - hack the digit drivers with 7seg? + */ + +/* pin assignments + * B[0,2]: serial clock for the 3 shift registers + * B4: SPI MISO connected to RTC I/O pin + * B5: SPI SCK connected to RTC serial clock + * + * C0: serial data for the 3 shift registers + * C1: hour separator LEDs + * C2: RTC chip select (active high) + * + * D[2,7]: nixie dots + */ +#define PB_CK1 0x01 +#define PB_CK2 0x02 +#define PB_CK3 0x04 +#define PB_RTC_DATA 0x10 +#define PB_RTC_CK 0x20 +#define PC_SDATA 0x01 +#define PC_HRSEP 0x02 +#define PC_RTC_EN 0x04 +#define PD_ADOT 0x04 +#define PD_BDOT 0x08 +#define PD_CDOT 0x10 +#define PD_DDOT 0x20 +#define PD_EDOT 0x40 +#define PD_FDOT 0x80 + +static void proc_cmd(char *input); + +static int echo; + +static char input[128]; +static unsigned char inp_cidx; + + +int main(void) +{ + /* SPI (SS/MOSI/SCK) are outputs */ + DDRB = ~PB_RTC_DATA; /* port B all outputs except the RTC data line */ + PORTB = 0; + DDRC = 0xff; /* port C all outputs */ + PORTC = 0; + DDRD = 0xff; /* port D all outputs */ + PORTD = 0; + + /* init the serial port we use to talk to the host */ + init_serial(38400); + sei(); + + for(;;) { + if(have_input()) { + int c = getchar(); + if(echo) { + putchar(c); + } + + if(c == '\r' || c == '\n') { + input[inp_cidx] = 0; + proc_cmd(input); + inp_cidx = 0; + } else if(inp_cidx < sizeof input - 1) { + input[inp_cidx++] = c; + } + } + } + return 0; +} + +static void proc_cmd(char *input) +{ + switch(input[0]) { + case 'e': + echo = input[1] == '1' ? 1 : 0; + printf("OK echo %s\n", echo ? "on" : "off"); + break; + + case '?': + puts("OK command help"); + puts(" e 0|1: turn echo on/off"); + break; + + default: + printf("ERR unknown command: '%c'\n", input[0]); + } +} diff --git a/fw/src/serial.c b/fw/src/serial.c new file mode 100644 index 0000000..3ca641a --- /dev/null +++ b/fw/src/serial.c @@ -0,0 +1,103 @@ +#ifndef F_CPU +#ifdef XTAL +#define F_CPU XTAL +#else +#warning "compiled for 1mhz internal rc osc. serial comms won't work" +#define F_CPU 1000000 +#endif +#endif + +#include +#include +#include +#include +#include + +static int uart_send_char(char c, FILE *fp); +static int uart_get_char(FILE *fp); + +#define BUF_SZ 16 +#define BUF_IDX_MASK (BUF_SZ - 1) +#define NEXT_IDX(x) (((x) + 1) & BUF_IDX_MASK) +static char outbuf[BUF_SZ]; +static volatile unsigned char out_rd, out_wr; +static char inbuf[BUF_SZ]; +static volatile unsigned char in_rd, in_wr; + +static FILE std_stream = FDEV_SETUP_STREAM(uart_send_char, uart_get_char, _FDEV_SETUP_RW); + + + +void init_serial(long baud) +{ + unsigned int ubrr_val = F_CPU / 16 / baud - 1; + + power_usart0_enable(); + + /* set baud generator timer reset value */ + UBRR0H = (unsigned char)(ubrr_val >> 8); + UBRR0L = (unsigned char)ubrr_val; + + /* enable rx/tx and recv interrupt */ + UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0); + /* set frame format: 8n1 */ + UCSR0C = 3 << UCSZ00; + + stdin = stdout = stderr = &std_stream; +} + +int have_input(void) +{ + return in_wr != in_rd; +} + +static int uart_send_char(char c, FILE *fp) +{ + /*int next;*/ + if(c == '\n') uart_send_char('\r', fp); + + while((UCSR0A & (1 << UDRE0)) == 0); + UDR0 = (unsigned char)c; +#if 0 + next = NEXT_IDX(out_wr); + while(next == out_rd); + + outbuf[out_wr] = c; + out_wr = next; + + /* enable the Tx data register empty interrupt */ + UCSR0B |= 1 << UDRIE0; +#endif + return 0; +} + +static int uart_get_char(FILE *fp) +{ + char c; + + while(in_rd == in_wr); + + c = inbuf[in_rd]; + in_rd = NEXT_IDX(in_rd); + return c; +} + +ISR(USART_RX_vect) +{ + char c = UDR0; + + inbuf[in_wr] = c; + in_wr = NEXT_IDX(in_wr); +} + +/* USART Tx data register empty (can send more data) */ +ISR(USART_UDRE_vect) +{ + if(out_rd != out_wr) { + UDR0 = outbuf[out_rd]; + out_rd = NEXT_IDX(out_rd); + } else { + /* no more data to send for now, disable the interrupt */ + UCSR0B &= ~(1 << UDRIE0); + } +} diff --git a/fw/src/serial.h b/fw/src/serial.h new file mode 100644 index 0000000..615626e --- /dev/null +++ b/fw/src/serial.h @@ -0,0 +1,7 @@ +#ifndef SERIAL_H_ +#define SERIAL_H_ + +void init_serial(long baud); +int have_input(void); + +#endif /* SERIAL_H_ */ diff --git a/hw/bom.ods b/hw/bom.ods new file mode 100644 index 0000000..c66620d --- /dev/null +++ b/hw/bom.ods @@ -0,0 +1,1300 @@ + + + + 2020-12-30T13:08:11.6864382512020-12-30T16:45:45.857555733PT21M28S4LibreOffice/7.0.4.2$Linux_X86_64 LibreOffice_project/00$Build-2 + + + 0 + 0 + 27509 + 20334 + + + view1 + + + 5 + 28 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 150 + 60 + true + false + + + nixiedisp + 1765 + 0 + 150 + 60 + false + true + true + true + 12632256 + true + true + true + true + false + false + false + 1270 + 1270 + 1 + 1 + true + false + + + + + true + true + true + false + 1270 + true + 1 + 12632256 + true + true + true + rgH+/0t5b2NlcmFfRlMtMTEwMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQ1VQUzpLeW9jZXJhX0ZTLTExMDAAAAAAAAAAAAAAAAAWAAMAywAAAAAAAAAIAFZUAAAkbQAASm9iRGF0YSAxCnByaW50ZXI9S3lvY2VyYV9GUy0xMTAwCm9yaWVudGF0aW9uPVBvcnRyYWl0CmNvcGllcz0xCmNvbGxhdGU9ZmFsc2UKbWFyZ2luZGFqdXN0bWVudD0wLDAsMCwwCmNvbG9yZGVwdGg9MjQKcHNsZXZlbD0wCnBkZmRldmljZT0xCmNvbG9yZGV2aWNlPTAKUFBEQ29udGV4RGF0YQpQYWdlU2l6ZTpMZXR0ZXIASW5wdXRTbG90OkludGVybmFsAAASAENPTVBBVF9EVVBMRVhfTU9ERRMARHVwbGV4TW9kZTo6VW5rbm93bg== + 1270 + 7 + false + true + true + 1 + true + + + en + US + + + + + + false + true + false + true + true + Kyocera_FS-1100 + false + 0 + 3 + true + false + false + false + true + false + true + + + + + + + + + + + + + + + + + + + + + + + + € + + + + - + + + € + + + + + + € + + + + - + + + € + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ??? + + + + Page 1 + + + + + + + ???(???) + + + 00/00/0000, 00:00:00 + + + + + Page 1/ 99 + + + + + + + + + + + + + + + + + + + + Reference + + + Quantity + + + Value + + + Footprint + + + Mouser id + + + Unit price + + + Cost + + + + + + + BT1 + + + 1 + + + 3V + + + CR2032 battery holder Keystone 1060 1x2032 + + + 534-1060TR + + + 1.380 € + + + 1.380 € + + + + + + C1 + + + 1 + + + 2.2nF + + + SMD 0805 + + + 187-CL21B222JBANNNC + + + 0.085 € + + + 0.085 € + + + + + + C11,C12 + + + 2 + + + 22pF + + + SMD 0805 + + + 80-C0805C220K1HACTU + + + 0.032 € + + + 0.064 € + + + (price for 10) + + + + + + C15 + + + 1 + + + 10nF + + + SMD 0805 + + + 581-08051C103K + + + 0.068 € + + + 0.068 € + + + + + + C16 + + + 1 + + + 2.2uF + + + radial D6.3mm P2.50mm + + + 647-UVR2E2R2MED1TD + + + 0.220 € + + + 0.220 € + + + + + + C2 + + + 2 + + + 0.33uF + + + SMD electrolytic 4x5.4 + + + 710-865230640003 + + + 0.152 € + + + 0.304 € + + + + + + C3-C7,C9,C10,C13,C14, C17-C34 + + + 27 + + + 0.1uF + + + SMD 0805 + + + 581-08055C104K + + + 0.034 € + + + 0.918 € + + + + + + C8 + + + 1 + + + 220uF + + + SMD electrolytic 8x10 + + + 647-UWT1E221MNL1GS + + + 0.347 € + + + 0.347 € + + + + + + D1 + + + 1 + + + 1N4148 + + + SMD SOD-323 (0805) + + + 750-1N4148WS-HF + + + 0.119 € + + + 0.119 € + + + + + + D4 + + + 1 + + + MUR160 + + + through hole diode + + + 863-MUR160G + + + 0.356 € + + + 0.356 € + + + + + + J1 + + + 1 + + + 12VDC IN + + + barrel jack 2mm center pin + + + 490-PJ-202A + + + 0.500 € + + + 0.500 € + + + + + + J2 + + + 1 + + + USB B Micro + + + USB Micro-B Molex-105017-0001 + + + 538-105017-0001 + + + 0.703 € + + + 0.703 € + + + + + + J4 + + + 1 + + + pwr sw + + + 1x2 pin header 2.54mm pitch vertical + + + 538-22-28-4112 + + + 0.398 € + + + 0.398 € + + + + + + J5 + + + 1 + + + HRLEDS + + + 1x3 pin header 2.54mm pitch vertical + + + 538-90147-1103 + + + 0.930 € + + + 0.930 € + + + + + + L1 + + + 1 + + + 220uH + + + Through-hole inductor radial D8.7mm P5.00mm + + + 815-AIUR-04-221J + + + 0.407 € + + + 0.407 € + + + + + + Q1 + + + 1 + + + MMBTA55 + + + SOT-23 + + + 863-MMBTA55LT1G + + + 0.169 € + + + 0.169 € + + + + + + Q2 + + + 1 + + + IRF540N + + + TO-220 + + + 942-IRF540NPBF + + + 0.788 € + + + 0.788 € + + + + + + Q3-Q68 + + + 66 + + + MMBTA42 + + + SOT-23 + + + 863-MMBTA42LT1G + + + 0.046 € + + + 3.036 € + + + (price for 100) + + + + + + R1-R3 + + + 3 + + + 1R + + + SMD 0805 + + + 603-RC0805FR-071RL + + + 0.044 € + + + 0.132 € + + + (price for 10) + + + + + + R15-R92 + + + 78 + + + 47k + + + SMD 0805 + + + 652-CR0805JW-473ELF + + + 0.004 € + + + 0.312 € + + + (price for 100) + + + + + + R4 + + + 1 + + + 1K + + + SMD 0805 + + + 71-CRCW08051K00JNEAC + + + 0.033 € + + + 0.033 € + + + (price for 10) + + + + + + R5,R6 + + + 2 + + + 330R + + + SMD 0805 + + + 652-CR0805JW-331ELF + + + 0.035 € + + + 0.070 € + + + (price for 10) + + + + + + R7 + + + 1 + + + 475K + + + SMD 0805 + + + 667-ERJ-6ENF4753V + + + 0.055 € + + + 0.055 € + + + (price for 10) + + + + + + R8 + + + 1 + + + 3K32 + + + SMD 0805 + + + 71-CRCW0805-3.32K-E3 + + + 0.048 € + + + 0.048 € + + + (price for 10) + + + + + + R9-R14 + + + 6 + + + 30k + + + SMD 0805 + + + 667-ERJ-6ENF3002V + + + 0.055 € + + + 0.330 € + + + (price for 10) + + + + + + U1 + + + 1 + + + Atmega328-AU + + + TQFP-32 + + + 556-ATMEGA328-AU + + + 1.550 € + + + 1.550 € + + + + + + U14,U17,U20,U23,U26,U29 + + + 6 + + + 74HC154 + + + SOIC-24 wide + + + 771-HC154D652 + + + 0.661 € + + + 3.966 € + + + + + + U15,U16,U18,U19,U21,U22,U24,U25,U27,U28,U30,U31 + + + 12 + + + 74HC04 + + + SOIC-14 + + + 595-SN74HC04DR + + + 0.229 € + + + 2.748 € + + + + + + U2 + + + 1 + + + MC34063AP + + + DIP-8 + + + 511-MC34063EBN + + + 0.500 € + + + 0.500 € + + + + + + U3 + + + 1 + + + 7805 + + + TO-220 + + + 863-MC7805CTG + + + 0.390 € + + + 0.390 € + + + + + + U32 + + + 1 + + + DS1302Z+ + + + SOIC-8 + + + 700-DS1302ZT&R + + + 2.740 € + + + 2.740 € + + + + + + U4 + + + 1 + + + MCP2221AxSL + + + SOIC-14 + + + 579-MCP2221A-I/SL + + + 1.600 € + + + 1.600 € + + + + + + U5,U6,U7 + + + 3 + + + 74HC164 + + + SOIC-14 + + + 771-74HC164D-T + + + 0.296 € + + + 0.888 € + + + + + + U8-U13 + + + 6 + + + IN14 + + + Nixie tube IN-14 + + + + 0.000 € + + + 0.000 € + + + + + + Y1 + + + 1 + + + 14.7456MHz + + + SMD Crystal ECS_CSM3X 2Pin 7.6x4.1mm + + + 815-ABLS7M-14.745B2T + + + 0.288 € + + + 0.288 € + + + + + + Y2 + + + 1 + + + 32.768KHz + + + SMD Crystal 2012 2Pin 2.0x1.2mm + + + 815-ABS0632768KHZ61T + + + 0.500 € + + + 0.500 € + + + + + + + + + + Total cost + + + 26.942 € + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hw/nixiedisp.sch b/hw/nixiedisp.sch index d7868b1..3f01b3b 100644 --- a/hw/nixiedisp.sch +++ b/hw/nixiedisp.sch @@ -1490,18 +1490,6 @@ F 3 "" H 1850 9750 50 0001 C CNN 1 0 0 -1 $EndComp Connection ~ 800 8200 -$Comp -L Device:C C4 -U 1 1 61166BC4 -P 1850 9900 -F 0 "C4" H 1965 9946 50 0000 L CNN -F 1 "0.1uF" H 1965 9855 50 0000 L CNN -F 2 "Capacitor_SMD:C_0805_2012Metric_Pad1.15x1.40mm_HandSolder" H 1888 9750 50 0001 C CNN -F 3 "~" H 1850 9900 50 0001 C CNN - 1 1850 9900 - 1 0 0 -1 -$EndComp -Connection ~ 1850 9750 Wire Wire Line 3350 8800 2900 8800 $Comp @@ -1750,23 +1738,23 @@ Wire Wire Line $Comp L power:GND #PWR019 U 1 1 61B0EE96 -P 3300 10950 -F 0 "#PWR019" H 3300 10700 50 0001 C CNN -F 1 "GND" H 3300 10800 50 0000 C CNN -F 2 "" H 3300 10950 50 0001 C CNN -F 3 "" H 3300 10950 50 0001 C CNN - 1 3300 10950 +P 3400 10950 +F 0 "#PWR019" H 3400 10700 50 0001 C CNN +F 1 "GND" H 3400 10800 50 0000 C CNN +F 2 "" H 3400 10950 50 0001 C CNN +F 3 "" H 3400 10950 50 0001 C CNN + 1 3400 10950 1 0 0 -1 $EndComp $Comp L power:VCC #PWR018 U 1 1 61B3194F -P 3300 10750 -F 0 "#PWR018" H 3300 10600 50 0001 C CNN -F 1 "VCC" H 3300 10900 50 0000 C CNN -F 2 "" H 3300 10750 50 0001 C CNN -F 3 "" H 3300 10750 50 0001 C CNN - 1 3300 10750 +P 3400 10750 +F 0 "#PWR018" H 3400 10600 50 0001 C CNN +F 1 "VCC" H 3400 10900 50 0000 C CNN +F 2 "" H 3400 10750 50 0001 C CNN +F 3 "" H 3400 10750 50 0001 C CNN + 1 3400 10750 1 0 0 -1 $EndComp Wire Wire Line @@ -1775,10 +1763,10 @@ Connection ~ 3700 8400 Wire Wire Line 3700 8400 3700 8500 Wire Wire Line - 3000 10750 3300 10750 + 3000 10750 3250 10750 Connection ~ 3000 10750 Wire Wire Line - 3000 10950 3300 10950 + 3000 10950 3250 10950 Connection ~ 3000 10950 Text Notes 2250 10550 0 50 ~ 0 bypass capacitors @@ -2068,4 +2056,33 @@ Wire Wire Line 3350 750 3400 750 Wire Wire Line 3400 750 3400 850 +$Comp +L Device:C_Small C4 +U 1 1 5FF08D11 +P 3250 10850 +F 0 "C4" H 3200 11000 50 0000 L CNN +F 1 "0.1uF" H 3150 10700 50 0000 L CNN +F 2 "Capacitor_SMD:C_0805_2012Metric_Pad1.15x1.40mm_HandSolder" H 3250 10850 50 0001 C CNN +F 3 "~" H 3250 10850 50 0001 C CNN + 1 3250 10850 + 1 0 0 -1 +$EndComp +Connection ~ 3250 10750 +Wire Wire Line + 3250 10750 3400 10750 +Connection ~ 3250 10950 +Wire Wire Line + 3250 10950 3400 10950 +$Comp +L Device:CP1 C35 +U 1 1 5FF65C5D +P 1850 9900 +F 0 "C35" H 2000 9900 50 0000 L CNN +F 1 "0.33uF" H 1900 9800 50 0000 L CNN +F 2 "Capacitor_SMD:CP_Elec_4x5.4" H 1850 9900 50 0001 C CNN +F 3 "~" H 1850 9900 50 0001 C CNN + 1 1850 9900 + 1 0 0 -1 +$EndComp +Connection ~ 1850 9750 $EndSCHEMATC -- 1.7.10.4