Skip to content

Commit 7c247fd

Browse files
committed
Increase CPU speed to 16 MHz. Add hardware documentation. (#6)
1 parent 4bb0288 commit 7c247fd

8 files changed

Lines changed: 110 additions & 17 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ set(CMAKE_C_COMPILER ${AVR_GCC})
3434

3535
set(DEVICE_MCU atmega1284p
3636
CACHE STRING "The MCU model to compile for.")
37-
set(DEVICE_F_CPU 8000000
37+
set(DEVICE_F_CPU 16000000
3838
CACHE STRING "The device's CPU frequency, in Hz.")
3939
set(DEVICE_BAUD 19200
4040
CACHE STRING "The default USART baud rate, in bits per second.")

Doxyfile.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
PROJECT_NAME = @PROJECT_NAME@
1414
OUTPUT_DIRECTORY = @CMAKE_CURRENT_BINARY_DIR@/docs
15-
INPUT = @CMAKE_SOURCE_DIR@/readme.md \
15+
INPUT = @CMAKE_SOURCE_DIR@/readme.md \
16+
@CMAKE_SOURCE_DIR@/doc \
1617
@CMAKE_SOURCE_DIR@/src
1718
RECURSIVE = YES
1819
EXTRACT_ALL = @DOXYGEN_EXTRACT_ALL@

doc/hardware.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# SuperKey Hardware
2+
3+
This page describes the SuperKey's hardware.
4+
5+
## Microcontroller
6+
7+
The SuperKey uses an [ATmega1284P microcontroller](https://www.microchip.com/en-us/product/ATmega1284p), currently
8+
produced by [Microchip Technology](https://www.microchip.com/). The datasheet for the ATmega1284P is available at
9+
[this link](https://ww1.microchip.com/downloads/en/DeviceDoc/ATmega164A_PA-324A_PA-644A_PA-1284_P_Data-Sheet-40002070B.pdf).
10+
The microcontroller uses a [dual inline package (DIP)](https://en.wikipedia.org/wiki/Dual_in-line_package)
11+
configuration, since this is the easiest type of integrated circuit for hobbyists to work with.
12+
13+
### Clock
14+
15+
The device uses a crystal oscillator with a frequency of 16 MHz as its primary clock inputs. This is connected to the
16+
`XTAL1` and `XTAL2` pins as shown in the schematic.
17+
18+
![Crystal Schematic](xtal.png "Crystal Schematic")
19+
20+
### Fuses
21+
22+
The microcontroller fuse configuration was calculated using [this site](https://www.engbedded.com/fusecalc/). The fuses
23+
are set for the following options:
24+
25+
- External Crystal Oscillator
26+
- Frequency 8.0+ MHz
27+
- Start-up time 16K clocks + 0 ms
28+
- Enable SPI programming
29+
- Enable JTAG
30+
- Enable brown-out detection at 2.7 V
31+
32+
This leads to the following fuse bytes:
33+
34+
- Low: `0xDF`
35+
- High: `0x99`
36+
- Extended: `0xFD`
37+
38+
The fuses can be programmed with the following `avrdude` command:
39+
40+
```
41+
avrdude -c avrispmkii -P usb -p m1284p -U lfuse:w:0xdf:m -U hfuse:w:0x99:m -U efuse:w:0xfd:m
42+
```
43+
44+
### Pinout
45+
46+
The pinout for the ATmega1284P is shown below:
47+
48+
![Device Pinout](pinout.png "Device Pinout")
49+
50+
### Pin Assignments
51+
52+
The current pin assignments are shown in the table below. Pins which are not listed are currently unassigned.
53+
54+
| Pin | Function | Description | Notes |
55+
|-----|----------|----------------------------|---------------------------|
56+
| 6 | `MOSI` | SPI Controller Out | Only used for programming |
57+
| 7 | `MISO` | SPI Controller In | Only used for programming |
58+
| 8 | `SCK` | SPI Clock | Only used for programming |
59+
| 9 | `RESET` | Reset Device | |
60+
| 10 | `VCC` | Power | |
61+
| 11 | `GND` | Ground | |
62+
| 12 | `XTAL2` | Crystal Oscillator Input 2 | |
63+
| 13 | `XTAL1` | Crystal Oscillator Input 1 | |
64+
| 14 | `RXD0` | Interface Port UART RX | |
65+
| 15 | `TXD0` | Interface Port UART TX | |
66+
| 16 | `RXD1` | Debug Port UART RX | |
67+
| 17 | `TXD1` | Debug Port UART TX | |
68+
| 19 | `OC1A` | Buzzer Output | |
69+
| 20 | `PD6` | Key LED | Active high |
70+
| 21 | `PD7` | Status LED | Active high |
71+
| 30 | `AVCC` | ADC Power | ADC is currently unused |
72+
| 31 | `GND` | Ground | |
73+
| 32 | `AREF` | ADC Reference Voltage | ADC is currently unused |
74+
| 33 | `PA7` | Output TRS Ring | |
75+
| 34 | `PA6` | Output TRS Tip | |
76+
| 35 | `PA5` | Input TRS 2 Ring | |
77+
| 36 | `PA4` | Input TRS 2 Tip | |
78+
| 37 | `PA3` | Input TRS 1 Ring | |
79+
| 38 | `PA2` | Input TRS 1 Tip | |
80+
| 39 | `PA1` | Input TRS 0 Ring | |
81+
| 40 | `PA0` | Input TRS 0 Tip | |
82+
83+
## Firmware Upload
84+
85+
The executable is uploaded to the MCU using [`avrdude`](https://www.nongnu.org/avrdude/) and an
86+
[AVRISP mkII programmer](https://a.co/d/59zSwb5).
87+
88+
```
89+
avrdude -c avrispmkii -P usb -p m1284p -U flash:w:superkey.ihex -D
90+
```

doc/pinout.png

214 KB
Loading

doc/userguide.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SuperKey User's Guide
2+
3+
This will be a user's guide some day.

doc/xtal.png

9.75 KB
Loading

readme.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ This will be a README someday.
99
[![Build - AVR ATmega1284P (Debug)](https://github.com/xchrishawk/superkey/actions/workflows/build-atmega1284p-debug.yaml/badge.svg)](https://github.com/xchrishawk/superkey/actions/workflows/build-atmega1284p-debug.yaml)<br/>
1010
[![Build - AVR ATmega1284P (Release)](https://github.com/xchrishawk/superkey/actions/workflows/build-atmega1284p-release.yaml/badge.svg)](https://github.com/xchrishawk/superkey/actions/workflows/build-atmega1284p-release.yaml)
1111

12-
## Notes
12+
## Documentation
1313

14-
### Upload Command
14+
- [User's Guide](doc/userguide.md) - User-focused instruction manual for the SuperKey.
15+
- [Hardware](doc/hardware.md) - Description of SuperKey hardware and its configuration.
1516

16-
The executable is uploaded to the MCU using [`avrdude`](https://www.nongnu.org/avrdude/) and an [AVRISP mkII programmer](https://a.co/d/59zSwb5).
17+
## Notes
1718

18-
```
19-
avrdude -c avrispmkii -P usb -p m1284p -U flash:w:superkey.ihex -D
20-
```
19+
### Upload Command

src/main/core/sys.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* @def DEBUG_TEST_CLOCK_WRAPAROUND
2727
* @brief If set to `ON`, the system tick will be set to 15 seconds prior to a wraparound at startup.
2828
*/
29-
#define DEBUG_TEST_CLOCK_WRAPAROUND ON
29+
#define DEBUG_TEST_CLOCK_WRAPAROUND OFF
3030

3131
/* --------------------------------------------------- VARIABLES ---------------------------------------------------- */
3232

@@ -105,22 +105,22 @@ void sys_init( void )
105105
//
106106
// Initialize timer 0 for main system tick at 1 millisecond period. Based on the following:
107107
//
108-
// - F_CPU = 8 MHz
109-
// - P_CPU = 1 / 8 MHz = 0.125 us
108+
// - F_CPU = 16 MHz
109+
// - P_CPU = 1 / 16 MHz = 62.5 ns
110110
// - Prescaler = F_CPU / 64
111-
// - P_TIMER = 0.125 us * 64 = 8 us
112-
// - Clocks = 1 ms / 8 us = 125
113-
// - OCRA = Clocks - 1 = 124
111+
// - P_TIMER = 0.05 us * 64 = 4 us
112+
// - Clocks = 1 ms / 4 us = 250
113+
// - OCRA = Clocks - 1 = 249
114114
//
115115
// Therefore we have:
116116
//
117117
// - Waveform generation mode set to CTC
118-
// - Clock prescaler set to F_CPU / 64 (F_CPU = 8 MHz)
119-
// - Compare value set to 124
118+
// - Clock prescaler set to F_CPU / 64 (F_CPU = 16 MHz)
119+
// - Compare value set to 249
120120
//
121121
TCCR0A = bitmask1( WGM01 );
122122
TCCR0B = bitmask2( CS00, CS01 );
123-
OCR0A = 124;
123+
OCR0A = 249;
124124

125125
// Enable interrupt for timer 0
126126
TIMSK0 = bitmask1( OCIE0A );

0 commit comments

Comments
 (0)