Commit MetaInfo

Revision2ab3c233ff4867acd451d60a8f6e9c550bd9134c (tree)
Time2019-01-27 18:08:52
Authoringlorion <homemicro@ingl...>
Commiteringlorion

Log Message

added ATmega programmer circuit

Change Summary

Incremental Difference

diff -r 7645f90241d8 -r 2ab3c233ff48 docs/design/atmega328-programmer.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/design/atmega328-programmer.txt Sun Jan 27 01:08:52 2019 -0800
@@ -0,0 +1,158 @@
1+* Circuit
2+
3+: /-----------------\
4+: | |
5+: | /-------------|---\
6+: | | | |
7+: | | |-ATmega--| | |
8+: | \-| 1 28 | | |
9+: R1 | | 2 27 | | |
10+: /---\/\/\/\/---+ | 3 26 | | |
11+: | | | 4 25 | | | / |--RPi GPIO--|
12+: | |-Osc-----| | | 5 24 | +---|---/ ---| 3.3V | 5V |
13+: \-| E Vcc |--+ | 6 23 | | | | 2 | 5V |
14+: | | \-----| 7 22 |-|-\ | | 3 | GND |
15+: | | /-| 8 21 |-+ | \---------| 4 | 14 |
16+: /-| GND OUT |------|-| 9 20 |-/ | | GND | 15 |
17+: | | | 10 19 |---|-----------| 17 | 18 |
18+: | | | 11 18 |---|-----------| 27 | GND |
19+: | | | 12 17 |---|-----------| 22 | 23 |
20+: | | | 13 16 | | | 3.3V | 24 |
21+: | | | 14 15 | | | 10 | GND |
22+: | | | | 9 | 25 |
23+: | | | | 11 | 8 |
24+: \------------------+---------------+-----------| GND | 7 |
25+: |------+-----|
26+: | 0 | 1 |
27+: | 5 | GND |
28+: | 6 | 12 |
29+: | 13 | GND |
30+: | 19 | 16 |
31+: | 26 | 20 |
32+: | GND | 21 |
33+
34+
35+* Operation
36+
37+ - The circuit operates at 3.3V, provided by the Raspberry Pi.
38+
39+ - Power is provided by one of the Raspberry Pi's 3.3V pins. There
40+ is a switch which allows cutting off the power to the ATmega and
41+ the oscillator.
42+
43+ - The oscillator should have a frequency of 10MHz or less. This
44+ allows the ATmega to operate at 3.3V.
45+
46+ - Check your oscillator's datasheet for the correct wiring. Common
47+ variations are needing pin 1 to be high or needing pin 1 to be left
48+ unconnected. The circuit diagram here shows pin 1 pulled high with
49+ pull-up resistor R1. The value of R1 is not very critical; I like
50+ to use 10K ohm, but any lower value should work, too, including
51+ wiring to Vcc directly - provided your oscillator actually needs the
52+ pin to be high.
53+
54+ - The oscillator's output is connected to ATmega pin 9 (XTAL1).
55+ This allows the programming circuit to function even when the
56+ ATmega is configured to use an external clock source.
57+
58+ - The ATmega is programmed using a serial protocol. It uses three
59+ signals: SCK (clock), MISO (data from the ATmega to the programmer),
60+ and MOSI (data from the programmer to the ATmega).
61+
62+ - SCK is provided by GPIO17 of the Raspberry Pi and connected to
63+ pin 19 of the ATmega.
64+
65+ - MISO is provided by GPIO27 of the Raspberry Pi and connected to
66+ pin 18 of the ATmega.
67+
68+ - MOSI is provided by GPIO22 of the Raspberry Pi and connected to
69+ pin 17 of the ATmega.
70+
71+ - The ATmega's reset# pin (pin 1) is held low during programming. This
72+ is controlled by GPIO4 of the Raspberry Pi.
73+
74+* Alternatives to 3.3V Oscillator
75+
76+The circuit runs at 3.3V, but many oscillator ICs want 5V. If you don't
77+have an oscillator that will work at 3.3V, there are several options.
78+Note that I have not tested any of these.
79+
80+If you have an oscillator that runs at 5V, one simple option is to
81+power the oscillator using one of the 5V pins on the Raspberry Pi and
82+run the oscillator's output through a voltage divider before feeding
83+it to the ATmega. Something like
84+
85+:
86+: 5V
87+: |
88+: +---------------\
89+: | |
90+: > |
91+: < R |
92+: > 1 |
93+: < |
94+: | |
95+: \---| E Vcc |-/
96+: | |
97+: | |
98+: /-| GND OUT |----\
99+: | |
100+: | >
101+: | < R
102+: | > 2
103+: | <
104+: | | to ATmega XTAL1 pin
105+: | +---------
106+: | |
107+: | >
108+: | < R
109+: | > 3
110+: | <
111+: | |
112+: +----------------/
113+: |
114+: -------
115+: ---
116+: -
117+
118+To get from 5V to 3.3V, you need R3 to have twice the resistance of
119+R2. Of course, resistors do not always have exactly the resistance
120+they are rated for. A 10% tolerance is common. At the same time, we
121+do not need to get to exactly 3.3V. Let's do some calculations.
122+
123+From the ATmega328 datasheet, we get that the absolute maximum voltage
124+on the XTAL1 pin is Vcc+0.5V. Assuming a 10% tolerance for the supply,
125+that means we want to go no higher than 3.3V * 90% + 0.5V = 3.47V. To
126+get that from a 5V supply with 10% tolerance, we need R3 / (R2 + R3)
127+to be at most 3.47 / 5.5, which means actual R2 >= (5.5 - 3.47) * R3 /
128+3.47. To account for resistor tolerances, we want rated R2 >= 1.21
129+nominal R2. This works out to rated R2/R3 >= 0.71.
130+
131+On the low side, we need a high signal to be at least 0.6Vcc to be
132+recognized as high by an ATmega running at 3.3V. This means we want at
133+least 3.3V * 110% * 0.6 = 2.18V. To get that from a 5V signal with 10%
134+tolerance, we need R3 / (R2 + R3) to be at least 2.18 / 4.5. Again
135+accounting for resistor tolerances, this means we need rated R2/R3 <=
136+0.86.
137+
138+For example, if we pick R3 rated 1.5K ohm and R2 rated 1.2K ohm, we
139+can expect an actual voltage between (5V * 0.9) * (1.5 * 0.9) / (1.5 *
140+0.9 + 1.2 * 1.1) = 2.28V and (5V * 1.1) * (1.5 * 1.1) / (1.5 * 1.1 +
141+1.2 * 0.9) = 3.32V, which is within the tolerances for XTAL1.
142+
143+(The above calculations ignore the impedance of XTAL1 itself, assuming
144+it is much higher than the resistor values being used here.)
145+
146+Another option would be to use a diode so that current can only flow from
147+the ATmega's XTAL1 pin to the oscillator's output and a pull-up resistor
148+to 3.3V on the XTAL1 pin. This way, when the oscillator output is low, it
149+drives the XTAL1 pin low, and when the output from the oscillator is high,
150+the pull-up resistor pulls XTAL1 to 3.3V.
151+
152+Yet another possibility is to use a 74LVC245 at 3.3V to drive XTAL1, with
153+the oscillator's output connected to the '245's 5V-tolerant inputs.
154+
155+Alternatively, you could build your own oscillator circuit that runs
156+at 3.3V. Possibilities here include using a crystal, a resonator, or
157+an LC circuit. The frequency on XTAL1 does not have to be very
158+precise, so this should work fine.
Show on old repository browser