Silicon ChipPIC/AVR Programming Adaptor Board; Pt.1 - May 2012 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Sound levels a sore point on TV and elsewhere
  4. Feature: The Australian Synchrotron by David Maddison
  5. Feature: Getting The Most From ADSL by Alan Ford
  6. Project: PIC/AVR Programming Adaptor Board; Pt.1 by Nicholas VInen
  7. Project: High-Temperature Thermometer/Thermostat by John Clarke
  8. Project: 1.5kW Induction Motor Speed Controller, Pt.2 by Andrew Levido
  9. Project: SemTest Discrete Semiconductor Test Set; Pt.3 by Jim Rowe
  10. Project: Ultra-LD Mk.3 135W/Channel Stereo Amplifier, Pt.3 by Nicholas Vinen
  11. Vintage Radio: Breville 730 dual-wave 5-valve receiver by Rodney Champness
  12. PartShop
  13. Order Form
  14. Advertising Index
  15. Outer Back Cover

This is only a preview of the May 2012 issue of Silicon Chip.

You can view 27 of the 112 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "PIC/AVR Programming Adaptor Board; Pt.1":
  • PIC/AVR Programming Adaptor Board PCB [24105121] (AUD $20.00)
  • PIC/AVR Programming Adaptor Board PCB pattern (PDF download) [24105121] (Free)
Articles in this series:
  • PIC/AVR Programming Adaptor Board; Pt.1 (May 2012)
  • PIC/AVR Programming Adaptor Board; Pt.1 (May 2012)
  • PIC/AVR Programming Adaptor Board; Pt.2 (June 2012)
  • PIC/AVR Programming Adaptor Board; Pt.2 (June 2012)
Items relevant to "High-Temperature Thermometer/Thermostat":
  • High Temperature Thermometer/Thermostat PCB [21105121] (AUD $20.00)
  • High Temperature Thermometer/Thermostat front & rear panels [21105122/3] (PCB, AUD $15.00)
  • High Temperature Thermometer/Thermostat PCB pattern (PDF download) [21105121] (Free)
  • High Temperature Thermometer/Thermostat front & rear panel artwork (PNG download) [21105122/3] (Free)
Items relevant to "1.5kW Induction Motor Speed Controller, Pt.2":
  • 1.5kW Induction Motor Speed Controller PCB [10105122] (AUD $35.00)
  • dsPIC33FJ64MC802-E/SP programmed for the 1.5kW Induction Motor Speed Controller [1010512B.HEX] (Programmed Microcontroller, AUD $25.00)
  • SL32 10015 NTC thermistor (Component, AUD $7.00)
  • Firmware for 1.5kW Induction Motor Speed Controller [1010512B.HEX] (Software, Free)
  • 1.5kW Induction Motor Speed Controller panel artwork and heatsink drilling template (PDF download) (Free)
Articles in this series:
  • 1.5kW Induction Motor Speed Controller, Pt.1 (April 2012)
  • 1.5kW Induction Motor Speed Controller, Pt.1 (April 2012)
  • 1.5kW Induction Motor Speed Controller, Pt.2 (May 2012)
  • 1.5kW Induction Motor Speed Controller, Pt.2 (May 2012)
Items relevant to "SemTest Discrete Semiconductor Test Set; Pt.3":
  • SemTest Upper PCB [04103122] (AUD $20.00)
  • SemTest Lower PCB [04103121] (AUD $20.00)
  • High Voltage Crowbar PCB [04105121] (AUD $7.50)
  • PIC16F877A-I/P programmed for the SemTest semiconductor test set [0410312B.HEX] (Programmed Microcontroller, AUD $20.00)
  • SemTest front panel [04103123] (PCB, AUD $50.00)
  • Firmware (ASM and HEX) files for the SemTest semiconductor test set [1410312B] (Software, Free)
  • High Voltage Crowbar PCB pattern (PDF download) [04105121] (Free)
  • SemTest Lower PCB pattern (PDF download) [04103121] (Free)
  • SemTest Upper PCB pattern (PDF download) [04103122] (Free)
  • SemTest front panel artwork and drilling template (PDF download) [04103123] (Free)
Articles in this series:
  • SemTest: A Discrete Semiconductor Test Set; Pt.1 (February 2012)
  • SemTest: A Discrete Semiconductor Test Set; Pt.1 (February 2012)
  • SemTest: A Discrete Semiconductor Test Set; Pt.2 (March 2012)
  • SemTest: A Discrete Semiconductor Test Set; Pt.2 (March 2012)
  • SemTest Discrete Semiconductor Test Set; Pt.3 (May 2012)
  • SemTest Discrete Semiconductor Test Set; Pt.3 (May 2012)
Items relevant to "Ultra-LD Mk.3 135W/Channel Stereo Amplifier, Pt.3":
  • Ultra-LD Mk3 200W Amplifier Module PCB [01107111] (AUD $15.00)
  • Input Switching Module PCB for the Low Noise Preamplifier [01111112] (AUD $15.00)
  • Input Selection Pushbutton PCB for the Low Noise Preamplifier [01111113] (AUD $5.00)
  • Ultra-LD Mk3/Mk4 Amplifier Power Supply PCB [01109111] (AUD $15.00)
  • Preamp & Remote Volume Control PCB for the Ultra-LD Mk3 [01111111] (AUD $30.00)
  • Ultra-LD Mk.3 Power Supply PCB pattern (PDF download) [01109111] (Free)
  • Ultra-LD Mk.3 Amplifier PCB pattern (PDF download) [01107111] (Free)
Articles in this series:
  • Ultra-LD Mk.3 135W/Channel Stereo Amplifier, Pt.1 (March 2012)
  • Ultra-LD Mk.3 135W/Channel Stereo Amplifier, Pt.1 (March 2012)
  • Ultra-LD Mk.3 135W/Channel Stereo Amplifier, Pt.2 (April 2012)
  • Ultra-LD Mk.3 135W/Channel Stereo Amplifier, Pt.2 (April 2012)
  • Ultra-LD Mk.3 135W/Channel Stereo Amplifier, Pt.3 (May 2012)
  • Ultra-LD Mk.3 135W/Channel Stereo Amplifier, Pt.3 (May 2012)

Purchase a printed copy of this issue for $10.00.

By NICHOLAS VINEN PIC/AVR Programming Adaptor Board Do you frequently program microcontrollers with a serial programmer? Want to streamline the process so you can quickly do virtually any micro? Well now you can! Our new Programming Adaptor Board, in combination with an In-Circuit Serial Programmer (ICSP), allows you to program most 8-bit & 16-bit PIC microcontrollers as well as 8-bit Atmel AVRs. It has a 40-pin ZIF socket and is configured with just a few DIP switches. M OST EMBEDDED developers program their microcontrollers using an In-Circuit Serial Programmer such as the Microchip PICkit3 or the Atmel AVRISP MkII. These plug into the USB port on your PC and a header on the development board. The PC software (eg, Microchip MPLAB or Atmel AVR Studio) is then used to 30  Silicon Chip program or re-program the microcontroller. This is handy while developing the project but you won’t always have a complete circuit with a programming header when you need to program a micro. It may be that the circuit operates at 230VAC mains potential and so you can’t safely plug a programmer in. Or perhaps the circuit connects the micro’s programming pins to other components which interfere with onboard programming. Maybe there just isn’t room for the programming header on the board because it wouldn’t fit or there is one but you can’t get to it once the board is mounted in its case. siliconchip.com.au So often, it’s just more convenient to pop the micro out and take it to a computer for programming. In short, there are lots of reasons why you might want to program a micro but an in-circuit programmer alone won’t do the job. That’s where this board comes in. It forms a circuit for the microcontroller to operate in and provides the programming header connection and power supply. Once it’s set up and the micro is locked into the ZIF socket, you fire up the serial programmer and program the chip as per usual. At SILICON CHIP we used to wire up a socket on Veroboard every time we wanted to program a new chip but this is a pain. There are so many different pin configurations and power supply requirements that you end up with dozens of the things floating around. You also have to bend the IC pins to get it into a standard socket and then it can be difficult to pull out without mangling them. Some programming adaptor boards available on the internet use multiple ZIF sockets to suit different micros. Unfortunately, good ZIF sockets are quite expensive so these boards usually use cheap ones which don’t last very long. And you’d need an awful lot of them to support a large portion of the PIC range. Features This programming board supports over 400 different 8-bit and 16-bit PICs – around 90% of the currently available range. It also supports about 45 different Atmel microcontrollers, covering most of the popular ATtiny and ATmega micros. It is capable of programming the vast majority of microcontrollers used in SILICON CHIP projects in the last 10 years or so. The programming adaptor board has a power supply since not all ICSP units can supply power to the micro. It also has soft-power control with over-current/short-circuit protection, to prevent damage to the micro in case something goes wrong. The on-board power supply can provide 3.3V or 5V, depending on what the micro to be programmed needs. In addition, the micro is always inserted into the ZIF socket with pin 1 at upper left, making it easy to use. Design Before drawing up the circuit, we siliconchip.com.au Main Features & Supported Microcontrollers Features • • • • • • • Runs off a 9-12V DC plugpack or USB 5V power Programs most Microchip PICs and Atmel AVR microcontrollers in DIP Selectable 3.3V or 5V micro power supply Easy configuration – chip type selected with 8-way DIP switch Electronic fuse protects micro Uses high-quality, reliable 40-pin universal ZIF socket Compatible with PICkit3 and AVRISP MkII Supported Microcontrollers • • • • Virtually all PIC12s, PIC16s and PIC18s Most PIC24s and dsPIC33s Most ATtinys and ATmegas Over 450 different microcontrollers supported – see panel on page 34 surveyed the entire range of 8-bit and 16-bit PICs and AVRs to figure out what proportion of the range we could support. There are nearly 500 different PICs in DIP packages with about 30 different pin configurations. The AVR range is smaller, with less than 100 parts and eight different pin-outs. Supporting them all is a huge ask but we figured that with 17 different pin configurations (13 for PICs and four for AVRs) we could cover about 90%, including all the most popular micros ranging from 8-pin up to 40pin DIP parts. We have to connect different pins to VCC and ground, depending on which micro is inserted. We also need to route the programming signals and voltages to the appropriate pins. For AVRs, it’s also useful to be able to drive the clock pins with a square wave during programming as they don’t automatically switch to the internal oscillator in programming mode (unlike PICs). Having sorted out what was required, the next question was how to achieve it. Essentially, what we need is a type of sparse crossbar or matrix switch – think of a telephone exchange. We have a 40-pin socket, two power supplies rails (0V and 3.3V/5V), three or four programming signals/ voltages and a couple of clock signals (we’ll explain that later). We need to connect some combination of these for a given micro and ideally this should not involve a lot of effort for the user. There are three obvious ways to do it: using jumper shunts, relays or electronic switches. We ruled the relay option out almost immediately; we would need at least 50 relays and it would have been a huge PCB. Jumper shunts would be a cheap and cheerful solution but then you, the user, would have to spend time reconfiguring the board one pin at a time, based on a whole series of diagrams. That would be a recipe for a disaster and besides, technology is supposed to make your life easier! So we decided on electronic switching using Mosfets. They are quite small and cheap and can easily be controlled by digital logic, making configuration a snap. Circuit description The resulting circuit is quite complicated, due to the large number of different configurations and how many pins need to be connected for each. So we have broken it up into sections, with Fig.1 showing the power supply switching and Fig.2 showing the control logic and serial data multiplexing. First, let’s examine IC1-IC3 in Fig.2. We are switching the serial programming signals using CMOS 1-to-8 analog multiplexer ICs (4051B). There are two such signals for PICs (PGD and PGC) and three for Atmel AVRs (MOSI, MISO and SCK). To simplify the circuit, we join PGD with MOSI and PGC with SCK; only one set is used at a time. These three programming lines are connected to the “Z” terminals on the ICs. The active-low enable pins of these three ICs (EN-bar) are joined together. When they are pulled low, the “Z” terMay 2012  31 minals are connected to one of the “Y” terminals. Which one depends on the state of input pins A0-A2. If A0-A2 are all low for one IC, its “Z” is connected to “Y0”. If S0 is high and the rest are low, giving a binary input of 1, “Z” is connected to “Y1” and so on. We have specified HEF­ 4 051Bs, which are pin-compatible with the original 4051Bs but have half the on-resistance between connected terminals (40Ω).This is important for reasons that will be explained later. The first three DIP switches in S1, labelled DIP0-DIP2, drive the A0-A2 inputs of these three ICs. The Y0-Y7 terminals of each are connected so that for each combination of DIP0-DIP2, one of the programming headers is connected to the appropriate pins for one type of micro. EN-bar is driven low simultaneously with the micro power supply being switched on, so that when the micro has no power, the programmer is disconnected. IC1-IC3 run from 16V, slightly higher than the normally specified 15V but below the 18V maximum. They can therefore not only pass the 3.3V or 5V digital signals but also withstand the 13.5V which can be applied to the MCLR/VPP pin when programming a PIC. In some cases, pin 1 is connected to VPP and this pin is also connected to IC1, so it must be able to withstand this voltage. Each programming pin connected to IC1-IC3 is also wired to a dual Schottky diode which is connected between the supply rails (D6-D8). These prevent the programmer (connected via CON1 or CON2) from driving the terminals of IC1-IC3 beyond their supply rails when the adaptor board power supply is switched off. Programming voltage The 13.5V mentioned earlier comes from the VPP pin of CON1, the ICSP header for PICs. This is used to power the micro’s internal flash programming circuit. Because the PIC draws some current from this rail during programming, we can’t use another HEF4051BT to route it, since the 40Ω series resistance would be an issue. Instead, we use discrete analog switches comprising surface-mount dual Mosfets Q18-Q21 – see upper left of Fig.1. Each pair is connected drain-todrain. One of the source terminals is connected to VPP on the programming 32  Silicon Chip socket while the other is connected to one of pins 1, 4, 9 or 10 on the ZIF socket. The gates are tied together. When the gates are held at 0V, both Mosfets are off since the source voltages are never below ground (0V). The body diodes are connected cathode-to-cathode so at least one is reverse biased and no current can flow through them either. When the gates are pulled up together to +16V, the gate-source voltages will be in the range of 2.516V, depending on the source voltages. These are in the range of 0-13.5V. Even with just 2.5V between gate and source, the FDS6912A Mosfets switch on, applying VPP to the connected pin. If the programmer pulls VPP low, the micro pin will also go low as the analog switch allows current to flow in either direction. When programming Atmel AVR microcontrollers, the reset pin is also used but the programmer only needs to pull it low, to enable the micro’s programming mode. We have provided a reset pushbutton (S4 in Fig.2) which also pulls this line to ground. Sometimes, when a micro is already running code, you need to do this before you initiate programming. There is a further difference with Atmel chips. If they have been configured to run from a crystal, ceramic resonator or external clock, they expect this to be present during programming as well as normal operation. This is in contrast to PICs which automatically switch to their internal oscillator when programming mode is enabled. So that you can still program chips set up in this way (and many will be), the adaptor board can supply a clock signal to the micro. This works even if it is expecting an external crystal; as long as it gets a square wave on both clock pins it will operate. This facility is provided by IC4 and IC5 which are also 4051Bs. When they are enabled, they apply the 1MHz square waves CLK and CLK-bar to the XTAL1 (clock input) and XTAL2 (clock output) pins of the micro. They are automatically disabled while programming PICs; CLKENA-bar and hence their EN-bar inputs are kept high. Switching power We also need to supply power to the micro. Some micros have a single pair of power supply pins (VCC and GND) while others can have multiples Fig.1: the ZIF socket and power supply switching (multiplexing) section of the programmer. The micro is placed in the 40-pin ZIF socket and Mosfets Q1a/ b-Q25a/b connect the various pins to VCC, GND and MCLR/VPP as required. Some Mosfets also connect capacitors between pairs of pins as necessaey. In addition, Mosfets Q26-Q29 connect serial programming lines PGC and PGD to pins 39 & 40 respectively, for high-speed programming of certain PICs. of each. These pins must have a low source impedance at high frequencies (1MHz+) or else the micro will not operate correctly. Normally, this is achieved by connecting power supply bypass capacitors between each pair of supply pins. But we can’t put capacitors directly between ZIF socket pins because while they may be used to supply power for one type of micro, another may use the same pins for serial programming. Large value capacitors would just shunt the programming signals to ground. Instead, we have connected multiple low-ESR bypass capacitors between the VCCS (micro power supply) and GND rails around the ZIF socket. We then switch those rails directly to the appropriate socket pins using low on-resistance Mosfets. The static on-resistance for the FDS6912As is about 0.02Ω and this is effectively in series with the bypass capacitor ESRs, for both VCC and GND pins. The total supply impedance is therefore quite low (<0.1Ω). In most cases, a single Mosfet switches power to one of the micro pins. For example, Q10a (right side) connects pin 36 to ground for MODE 2 while Q3b connects the same pin to VCCS in MODE 3. In both cases, the gate is pulled to +16V to turn the Mosfet on and to 0V to turn it off. However, for pins which share VPP (~13.5V) and VCCS (3.3V/5V), two Mosfets are connected drain-to-drain for VCCS, just as they are to supply VPP. For example, Q22a & Q22b (upper left) connect pin 1 to VCCS. This is necessary to prevent the higher VPP voltage from feeding back into VCCS when it is turned on. In total, there are 13 Mosfets connecting various pins to VCCS and 12 for GND. Then there are an additional six siliconchip.com.au G S +2.5V Q16b D MODE 9C G S S 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 Q3b Q24a Q10b D Q4b Q15b D Q25a S 220nF G D G S Q23b Q5b G FROM IC3 PIN 1 S G S S MODE 1,6,7A,7C,9 G MODE 6 D FROM IC2 PIN 1 Q14a Q23a G FROM IC1 PIN 1 FROM IC5 PIN 12 S FROM IC4 PIN 12 S VPP PIC/AVR PROGRAMMER siliconchip.com.au G S S Q11a MODE 2 D D G D MODE 8 S MODE 1 S D G Q26-29: 2N7002P G S G MODE 6 S D ZIF SOCKET & MULTIPLEXING Vccs D VPP G Q8b D D Q2a S S Q11b MODE 6 S Q2b G Q21b Vccs Q21a Q20a G Q20b S G MODE 7A D D MODE 7 MODE 1,4,9 S D Q14b Q7b G Vccs FROM IC4 PIN15 SC S MODE 4 G S MODE 7B,7C S Q8a G D 10F D D D D D G D G S D MODE 1 S G G D Q25b Vccs D G MODE 2 S Q15a Q12b Q12a G S G D S D S G MODE 3 S D G Q1a G Vccs D S MODE 1A D G 2012 FROM IC2 PIN 13, IC3 PIN 5 FROM IC1 PIN 13 10F S FROM IC3 PIN2, IC4 PIN14 FROM IC5 PIN14 FROM IC1 PIN 14 S S MODE 4 MODE 6 G FROM IC1 PIN 12 FROM IC3 PIN 12 D D MODE 9A MODE 5A Q5a S G MODE 4,7,9 G FROM IC1 PIN 5, IC3 PINS 13,14 10F 220nF FROM IC2 PIN2, IC5 PIN15 Q9a S Q7a G MODE 9B,9C MODE 5 S D MODE 2 G Q3a Q27 Q29 MODE 1,9 Q24b FROM IC1 PIN 2 G S Q10a Q6a D G MODE 0,7,8 Q4a S MODE 3 G 470nF 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 D G S S Q1b FROM IC3 PIN4, IC5 PIN1 S D 40-PIN ZIF SOCKET FROM IC3 PIN 15 MODE 2 10F D D S D MODE 0 FROM IC2 PIN 15, IC4 PIN13 G Q6b FROM IC1 PIN 15 MODE 7 G Vccs D Q13b G G S D D D PGD S Q13a FROM IC1 PIN 4, IC4 PIN1 VPP S G MODE 3,5 Vccs G D D Q28 G Q9b S Q19b S G D D D Q19a D PGC S 4x 100nF G MODE 5 Q18a Q22a D D G Vccs S Q18b Q22b S Q26 VPP MODE 0,1,4,7,8,9 G G Q1-25: FDS6912A Db Db Da Da Gb Sb SaGa May 2012  33 Supported Microcontrollers [x = any digit, (A) = with or without A suffix] Microchip PIC12F, PIC12HV: All [25] PIC16F, PIC16LF, PIC16HV: All but PIC16F57 and PIC16F59 [149] PIC18L, PIC18LF: All* [132] PIC24E: All [8] PIC24F: All** but PIC24F04KA20x, PIC24F04KLx00 and PIC24FJ16MC101 [29] PIC24H: All but PIC24HJ12GP20x [14] dsPIC33E: All [12] dsPIC33F: All but dsPIC33FJxxGSxxx and those ending with -101 [26] * PIC18F2331, PIC18F44J10 and PIC18F45J10 require an extra component in the ZIF socket. ** PIC24FxxKA30x (12 types) require an extra component in the ZIF socket. Atmel ATtiny13(A)(V), ATtiny15L, Attiny25/45/85(V) [10] ATtiny261/461/861(A)(V) , Attiny26(L) [11] ATtiny2313(A)(V), Attiny4313 [4] ATtiny48/88, Atmega48/88/168/328(P)(A)(V), Atmega8(A)(L) [21] ATmega16/32(A)(L), Atmega164/324/644/1284(P)(A)(V) [20] ATmega8535(L) [2] Total: 463 fully supported, 15 programmable with additional components Note: some parts no longer in production have not been checked but are likely to work. dual Mosfets (ie, a total of 12) which connect various capacitors between pins as required for some micros. These latter FETs are all configured as analog switches, in series with the capacitors. For example, Q12 (left side) connects a 10µF capacitor between pins 6 and 8, to filter the core supply voltage of certain micros (dsPIC33s and PIC24s). Q16b supplies 2.5V to pin 6 if required. Q14a is unused and has its gate and source tied to ground. Three additional Mosfets are used in the power supply, to be described later. In total, there are 25 FDS6912A dual Mosfets surrounding the ZIF socket. This may seem like a lot but they are relatively cheap. Parasitic capacitance The problem with all these Mosfets is that even when switched off, they are effectively still present in the circuit. While the drain-source leakage current is very low and can be ignored, the output capacitance is an issue. This refers to the capacitance seen at the drain pin which is the sum of the drain-source and drain-gate capacitances. This capacitance is highest (about 34  Silicon Chip 1nF) when the Mosfet’s drain-source voltage is zero. As the drain-source voltage increases, it drops to about 150pF. With multiple Mosfets on a single pin, this can add up and in combination with the 40Ω resistance of the analog multiplexer ICs, IC1-IC5, it forms low-pass filters for the serial programming and clock signals. This limits the signals passed to a maximum of about 1.5MHz. In most cases, this is not a problem. We tested the programming adaptor board with a variety of PIC and AVR chips (about 20 different types), using the PICkit3 and AVRISP MkII serial programmers. We found the programming speed was typically around 0.5MHz and it worked reliably in each mode. There is one situation where the parasitic capacitance is an issue and this is when programming PIC18FJ devices. The PICkit3 uses a higher clock frequency for these, of about 2MHz. It is therefore necessary to have four small additional Mosfets, Q26-Q29. They form analog switches in parallel with IC1 and IC3, for routing the PGD and PGC signals to pins 40 and 39 respectively. For PIC18FJs then, the series re- sistance to the programming signals drops to a couple of ohms, allowing the higher frequency signals to pass through. These four additional Mosfets are 2N7002Ps. The 2N7002 is a surfacemount version of the 2N7000. The P suffix is important as it indicates a lower on-resistance (1Ω compared to 2.5Ω) which is required for reliable programming of PIC18FJs. Control logic All this switching is controlled by the circuitry shown in Fig.2. To program a particular micro, eight DIP switches (S1) are set to the appropriate positions. Each DIP switch is connected to a pull-down resistor, so if the DIP switch is off, the corresponding line labelled DIP0-DIP7 is 0V and if the switch is on, the line is at 16V. DIP0-DIP3 configure the analog multiplexers IC1-IC5, described earlier, They are also connected to the four inputs (A0-A3) of CMOS 4028B BCDto-decimal decoder IC6. Depending on the positions of DIP0-DIP3, one of its 10 outputs (O0-O9) is high and the rest are low. These outputs then drive the gates of some of the Mosfets shown in Fig.1, turning the appropriate ones on for that mode. For example, in MODE 5, output O5 of IC6 goes high and turns on Mosfet Q9a, which connects pin 40 of the ZIF socket to ground. Some Mosfets must be turned on in more than one mode and so the 10 mode lines are also fed into nine OR gates: IC7a-IC7c, IC8aIC8c and IC9a-IC9c. In some cases, these are cascaded. So when MODE 1, 4 or 9 is selected, the output of IC9b (MODE 1,4,9) is high and this turns on Mosfet Q4b, supplying 3.3V or 5V to pin 32 of the micro. But the scheme described above only gives us 10 possible pin configurations and as we said earlier, we need 17. The additional seven configurations use the same power and programming pins as the other 10 but involve different combinations of capacitors connected between other pins and, in one case, an additional 2.5V supply. The extra control signals are derived from the 10 mode signals and the positions of two more DIP switches, DIP4 and DIP5. This is achieved using eight 2-input AND gates, IC10a-IC10d and IC11a-IC11d, in combination with inverter gates IC12a-IC12c and 2-input siliconchip.com.au Parts List 1 PCB, code 24105121, 116 x 127mm (available from SILICON CHIP) 1 40-pin Universal ZIF socket, 0.6-inch wide pin spacing (Element14 1169111) 1 40-pin production DIL socket, 0.6-inch wide pin spacing 1 220µH bobbin inductor (Jaycar LF1104, Altronics L 6225) 1 1MHz or 1.008MHz crystal or 2-pin ceramic resonator (Rockby 10234, 13390 or 10233) 1 100kΩ 9-pin 8-resistor network (Element14 9356827) 1 6-way pin header strip (CON1) 2 10-way shrouded vertical IDC socket (CON2) 1 PCB-mount USB type B socket (CON3) 1 PCB-mount DC socket (CON4) 1 2-way polarised header, 2.54mm pitch (CON5) 1 3-way pin header strip and shorting block (LK2) 1 8-way DIP switch (S1) (Element14 1123941; Jaycar SM1024; Altronics S3060) 3 PCB-mount tactile pushbuttons (S2-S4) 1 miniature PCB-mount SPDT slide switch (S5) (Element14 1123875) 5 M3 x 6mm machine screws 1 M3 shakeproof washer 1 M3 nut 4 M3 x 12mm tapped Nylon spacers Semiconductors 5 HEF4051BT 8-way analog multiplexers [SOIC-16] (IC1IC5) (Element14 1201291) OR gate IC7d. The additional modes are labelled A, B and C and are selected by switching DIP4 on (mode A), DIP 5 on (mode B) or both on (mode C). If MODE 9 is selected and both DIP4 and DIP5 are on (high), the output of AND gate IC10a (MODE 9B,9C) is high, as is the output of AND gate IC10c (MODE 9A,9C). As a result, the output of IC10b (MODE 9C) is also high. With MODE 9B,9C and MODE 9C both high, Mosfets Q12a and Q12b connect a 10µF capacitor between pins 8 and 6 while at the same time, Q16b turns siliconchip.com.au 2 CD4028BM BCD-to-decimal decoders [SOIC-16] (IC6, IC17) (Element14 1753401) 2 HEF4071BT quad 2-input OR gates [SOIC-14] (IC7, IC8) (Element14 1085289) 1 CD4075BM triple 3-input OR gate [SOIC-14] (IC9) (Element14 1739910) 2 HEF4081BT quad 2-input AND gates [SOIC-14] (IC10, IC11) (Element14 1085290) 1 HEF4069UBT hex inverter [SOIC-14] (IC12) (Element14 1201295) 1 SN74HC04D hex inverter [SOIC-14] (IC13) (Element14 1311424) 1 HCF4013BM1 dual D-type flipflop [SOIC-14] (IC14) (Element14 1094187) 1 OP07CD precision op amp [SOIC-8] (IC15) (Element14 1575526) 1 LM293D dual low-power comparator [SOIC-8] (IC16) (Element14 2292944) 1 7805T 5V 1A linear regulator (REG1) 1 AP1117E33 3.3V low-dropout linear regulator [SOT-223] (REG2) (Element14 1825291) 1 SPX1117M3-L-2-5 2.5V low-dropout linear regulator [SOT-223] (REG3) (Element14 1831943) 1 MC34063ADG switchmode controller [SOIC-8] (REG4) (Element14 1211119) 25 FDS6912A dual independent N-channel Mosfets [SOIC8] (Q1-Q25) (Element14 1095019) 4 2N7002P N-channel Mosfets [SOT-23] (Q26-29) (Element14 1859848) on, supplying 2.5V to pin 6. This suits PIC18LF2xJ5x microcontrollers. Inverter stages IC12e and IC12f are unused, so their inputs are tied to +16V to prevent oscillation. Two-input OR gate IC8d is also unused and connected similarly. a 1MΩ biasing resistor and a 4.7kΩ current-limiting resistor. The 1MHz clock signal is then buffered by IC13b and IC13f which are paralleled for increased drive strength. This signal then passes to IC5, to be connected to the micro’s XTAL1 (clock input) pin, when enabled. This clock signal is inverted again, by IC13c-IC13e (also paralleled) and this signal passes to IC4, which routes it to the micro’s XTAL2 (clock output) pin, if enabled. Both inverters must charge and Clock generator Fig.2 also shows the crystal oscillator circuit which is based on hex inverter IC13, a 74HC04D. IC13a forms the oscillator in combination with crystal X1, two 33pF load capacitors, Diodes & LEDs 1 1N5819 1A Schottky diode (D1) 3 1N4148 small diodes (D2-D4) 1 1N4004 1A diode (D5) 3 BAT54S dual series Schottky diodes [SOT-23] (D6-D8; Element14 1467519) 1 Green 3mm LED (LED1) 1 Yellow 3mm LED (LED2) 1 Red 3mm LED (LED3) Capacitors 4 100µF 16V electrolytic 2 47µF 25V electrolytic 1 10µF 16V electrolytic 4 10µF 6.3V SMD X5R ceramic [3216/1206] (Element14 1833825) 1 470nF MKT 2 220nF 50V SMD X7R ceramic [3216/1206] (Element14 1362557) 11 100nF 50V SMD X7R ceramic [3216/1206] (Element14 1301906) 14 100nF MKT 1 470pF disc ceramic 2 33pF disc ceramic Resistors (1%, 0.25W) 1 1MΩ 1 4.7kΩ 1 100kΩ 3 2.2kΩ 1 68kΩ 1 1.1kΩ 5 47kΩ 2 1kΩ 1 13kΩ 1 220Ω 1 1Ω (1% or 5%) 1 0.1Ω SMD [3216/1206] (Element14 1865244) May 2012  35 2 6 4 3 1 8 5 10 12 14 16 7 100nF S1 DIP SWITCH 16 Vdd DIP7 O7 DIP6 O6 11 DIP3 12 DIP2 13 DIP1 10 DIP0 8 5 MODE 9 A3 O3 A2 O2 A1 O1 A0 O0 Vss 8 RN1 8x100k 10 9 MODE 8 4 MODE 7 2 7 MODE 6 IC12c IC10a 5 15 MODE 3 2 MODE 2 12 14 MODE 1 1 3 MODE 0 IC11d 4.7k X1 1.0MHz 33pF 14 11 IC12a IC11a 3 1 2 IC13b 5 9 11 IC13c IC13d IC13e 14 13 14 IC7c 2 1 IC9b 11 MODE 9 MODE 7 13 12 IC9c MODE 8 6 1 7 IC8d IC8a 6 3 SC 10 MODE 4,7,9 IC8b 4 MODE 0,1,4,7,8,9 MODE 5 9 MODE 3 8 IC8c MODE 3,5 10 +16V CLK 10 100nF 8 9 DIP4 MODE 7 10 MODE 0 IC12f MODE 8 5 6 1 RESET S4 3 D6 2 PIC/AVR PROGRAMMER IC7b 4 1 14 IC7a 5 3 4 5 MODE 1A MODE 0,7,8 MODE 0,8 7 +16V Vdd 1 6 4 2 VPP PGD PGC MODE 5A IC11b CON1 1 2 3 10 IC11c 6 MODE 1 12 PIC ICSP 2012 MODE 1,4,9 5 8 +16V IC10, IC11: 4081B IC7, IC8: 4071B IC9: 4075B IC12: 4069B IC13: 74HC04D 6 7 2 IC12e 11 9 MODE 1,6,7A,7C,9 IC9a MODE 9 MODE 4 CLK 4 14 4 5 3 100nF 11 MODE 7A MODE 1,9 8 MODE 6 12 100nF 12 7 10 MODE 5 14 4 7 100nF +16V 13 12 IC12b 11 3 +16V MODE 1 8 7 33pF IC7d 7 MODE 9 9 IC13f 3 7 6 13 2 100nF 13 MODE 9A IC10d MODE 7A,7C 1M 2 IC10b MODE 7B,7C 13 Vcc IC13a MODE 9B,9C MODE 9C 11 13 100nF 1 4 6 12 3 6 MODE 5 14 5 IC10c 1 IC6 O5 4028B O4 1 MODE 4 DIP5 DIP4 9 DIP4 DIP5 O9 O8 9 11 13 15 100nF 3 1 D7 2 3 D8 2 2 4 6 8 10 CON2 1 MOSI 3 5 RESET 7 SCK 9 MISO AVR ICSP CONTROL LOGIC Fig.2: the control logic for the adaptor board is shown at left, while IC1-IC5 (HEF4051Bs) connect the serial programming and clock lines to various pins on the ZIF socket (see Fig.1). 8-way DIP switch S1 selects the micro to be programmed and the switch states are decoded using the various logic ICs, to drive the appropriate Mosfets and analog switches. 36  Silicon Chip siliconchip.com.au +16V 100nF 16 Vdd CLKENA 6 DIP3 9 Y7 Y6 EN Y5 A2 Y4 A0 Y2 4 2 5 ZIF SOCKET PIN 5 1 IC5 10 12 A1 4051B Y3 DIP2 11 CLK 3 Y1 Z Vss 8 Vee 7 Y0 ZIF SOCKET PIN 13 15 ZIF SOCKET PIN 7 14 ZIF SOCKET PIN 9 13 +16V 16 Vdd 6 9 100nF Y7 Y6 EN Y5 A2 Y4 A0 Y2 Z Y0 4 2 5 ZIF SOCKET PIN 4 1 IC4 10 12 A1 4051B Y3 DIP1 11 CLK 3 Y1 Vss 8 Vee 7 ZIF SOCKET PIN 12 15 ZIF SOCKET PIN 10 14 ZIF SOCKET PIN 8 13 ZIF SOCKET PIN 2 Power supply +16V ENABLE DIP0 16 Vdd DIP1 DIP2 6 9 100nF Y7 Y6 EN Y5 A2 Y4 4 2 ZIF SOCKET PIN 6 5 ZIF SOCKET PIN 39 1 ZIF SOCKET PIN 29 IC1 10 12 A1 4051B Y3 11 3 Y2 A0 Y1 Z Vss 8 Vee 7 Y0 ZIF SOCKET PIN 35 15 ZIF SOCKET PIN 1 14 ZIF SOCKET PIN 40 13 ZIF SOCKET PIN 37 +16V 16 Vdd 6 9 100nF Y7 Y6 EN Y5 A2 Y4 A0 Y2 Z Y0 4 2 5 ZIF SOCKET PIN 30 1 IC2 10 12 A1 4051B Y3 11 3 Y1 Vss 8 Vee 7 15 14 ZIF SOCKET PIN 38 13 +16V 16 Vdd 6 9 10 11 3 100nF Y7 Y6 EN Y5 A2 Y4 A0 Y2 4 2 5 1 IC3 12 A1 4051B Y3 Y1 Z siliconchip.com.au Vss 8 Vee 7 Y0 15 ZIF SOCKET PIN 31 ZIF SOCKET PIN 34 D6-7-8: BAT54S 3 1 2 Refer now to Fig.3 which shows the power supply. The unit can run from either a 9-12V DC plugpack or a USB port. The plugpack is connected to CON4 and this disconnects the USB ground pin so that power can’t flow back into the USB port. D5 provides reverse polarity protection and REG1 then drops the supply voltage to the required 5V. For USB, 5V is drawn straight from the socket. Either way, slide switch S5 acts as the power switch and when on, green LED1 lights up. The 5V rail is reduced to 3.3V by REG2, a low-dropout (LDO) linear regulator. These 5V and 3.3V rails provide the two power options for the micro. The 5V rail also powers REG4, an MC34063 switchmode regulator. This switches current through inductor L1 (a 220µH choke) and in combination with Schottky diode D1, generates the +16V logic supply. This only needs to deliver a few milliamps since the logic is all static. The ratio of the 13kΩ and 1.1kΩ resistors sets the output voltage to 1.25 x (13kΩ ÷ 1.1kΩ + 1) = 16.02V. LK1 allows the power supply to be tested before voltage is applied to the rest of the circuitry. This is shorted for normal operation. Voltage selection ZIF SOCKET PIN 3 14 13 discharge the parasitic capacitance at the target pin at 1MHz. This could be a couple of nanofarads. Their load impedance can be up to 40Ω + (1 ÷ (2π x 1MHz x 2nF)) = 120Ω, hence the use of multiple inverters in parallel. Unfortunately, 1MHz crystals are not as common as 2MHz crystals. The circuit will work with a 2MHz crystal but the dissipation in IC4 and IC5 increases due to the increased current required to drive the load capacitance at the higher frequency. We did not experience any failures in our prototypes but cannot vouch for the long-term reliability of the circuit if using such a crystal. If you do use a 2MHz crystal, avoid leaving the clock and micro power enabled for long periods, when programming at 5V. This is not an issue when programming PICs. Mosfets Q17a and Q17b switch the 3.3V and 5V rails to the micro respectively; only one can be on at a time. Q17a turns on when DIP6 is high but Q17b is only indirectly controlled by May 2012  37 38  Silicon Chip siliconchip.com.au Ct GND 4 Cin5 REG4 MC34063 SwE A +2.2V Vcc 100nF K A 1k (Rshunt) 0.1 1.1k 13k K POWER SUPPLY 47k D2 1N4148 CON5 1 2 IC15: OP07CD 2 1 K  A D1 1N5819 LED1 +2.2V 1k S5 POWER 100F 16V L1 220H SwC 8 DrC 7 Ips 6 220 GND OUT Vcc 1 IN REG1 7805 PIC/AVR PROGRAMMER 470pF 3 100nF 47F 25V K 6 5 3 2 2 3 7 3 1 6 4 IC16b 7 +5V 47k IC16: LM293D IC16a 8 1 8 TPG 1 +3.3V A DIP6 MODE7 S D K 47k 2.2k G A K 11 10 13 12 A O6 O7 O8 O9 Vss 5 6 7 4 9 S D R Q Q 2 1 100nF Q LED3 13 IC14: 4013B IC14b CLK IC14a 14 Vdd 3 14 2 15 K 11 CLK 12 Q 10 R Vss 7 9 8 47k 4 3 6 S 5 D 8 O1 O0 A1 A0 O2 O3 A2 A3 Vdd 16 IC17 O5 4028B O4 1 1N5819 D4 1N4148 100nF 100nF DIP7 MODE9BC 1N4148 47k S3 OFF S2 ON 100nF S D 100F 16V +16V G 4 2 +16V OUT OUT GND TP1 IN REG2 AP1117E33 100nF 68k 4 IC15 47F 25V LK1 100F 16V +5V A K 1N4004 K  A 2.2k K  LED2 A 2.2k K 4 2 Db Db Da Da 1 GND OUT OUT 10F LK2 A K A IN GND 8 LEDS IC12d OUT 7805 +2.5V ENABLE CLKENA DIP4 Vcc Vdd Vccs +16V GND TAB (OUT) AP1117E33, SPX1117M3-L-2.5 9 100k S D GND OUT IN 1 2 3 G Q16a Gb Sb SaGa Q16,Q17: FDS6912A IN D3 1N4148 100nF 3 REG3 SPX1117M3-L-2.5 Fig.3: the adaptor power supply. Power comes from a 9-12V DC plugpack or a USB cable. From these, 16V, 5V, 3.3V and 2.5V rails are generated. 16V powers the logic while the rest can supply the micro. IC14 controls power to the micro with IC15 and IC16 monitoring the current flow. If the current limit is exceeded, IC14 turns the power off and turns on red LED3. 2012 SC  4 1 100F 16V CON3 USB POWER CON4 A D5 1N4004 Q17a DC POWER Q17b DIP7. IC17, another 4028B BCD-todecimal decoder, is between the two. We don’t want Q17b to turn on if Q17a is on as this would short the 3.3V and 5V supplies together. Q17b is also disabled if the programmer has been set up for a micro which will be damaged by 5V. So for Q17b to come on, DIP6 must be off, DIP7 on and neither Mode 7 (for dsPIC33s) nor Modes 9B or 9C (for PIC24s) should be enabled. Since Q17b’s gate is connected to output O1 (pin 14) of IC17, it will only turn on if input A0 is high and inputs A1-A3 are low, giving a binary input value of 1. This can only occur under the conditions specified above. Electronic fuse Whichever supply voltage is selected, current then flows from Q17a or Q17b through Rshunt (0.1Ω) and then through Q16a, to the micro’s VCCS (switched VCC) supply. Q16a is the soft-power switch and this allows power to the micro to be cut quickly in an over-current condition. This condition is detected by the voltage across Rshunt rising to a certain level. The voltage across it is amplified by precision op amp IC15 and monitored by comparator IC16a. With 100mA through Rshunt, there is just 10mV across it. If IC16a monitored this directly, its maximum offset voltage of ±9mV would mean an error of up to ±90mA. That’s clearly too much, given that we want a nominal current limit of around 100mA. By comparison, IC15 has a very low maximum input offset voltage (0.15mV). It is configured for a gain of 69, ie, (68kΩ + 1kΩ) ÷ 1kΩ. This reduces the error due to IC16b’s offset voltage to around ±1.5mA. A 100nF feedback capacitor provides a time delay (of about 1ms) so that very brief current transients do not trip the current limit. This is necessary since when power is first applied, the charging of the supply bypass capacitors causes a brief current spike which could otherwise cause a nuisance trip. IC15’s output is relative to VCC and is negative, ie, the more current that flows through Rshunt, the lower IC15’s output voltage is. The reference voltage it is compared against must also be relative to VCC and this is generated with small signal diode D2 and a 47kΩ load resistor. The drop across this 1N4148 diode is quite predicable at around 0.6V. In combination with IC15’s gain, this sets the current limit to about 90mA (0.6V ÷ 69 ÷ 0.1Ω). If the micro draws any more than this during programming, IC16a’s output goes high and the supply switches off. This was sufficient for programming all micros that we tested. There is an additional consideration; when the micro supply is off, input pins 2 and 3 of op amp IC15 are outside its normal operating range (115V). Its output is therefore undefined and it could switch power off before VCC rises to a normal level. Comparator IC16b prevents this. It compares VCC against the 2.5V rail and so its output remains low until VCC rises above the 2.2V reference derived from LED1. Since the outputs of IC16a and IC16b are connected together, this prevents the over-current signal from being asserted until the supply voltage is high enough for IC15 to monitor the current through Rshunt. Power control IC14a is a flipflop which drives the gate of Q16a and hence controls power to the micro. Its pin 4 reset input is driven by comparator IC16a, mentioned earlier. If excessive current flow is detected and IC16a’s output goes high, the 47kΩ resistor pulls pin 4 of IC14a high and this resets IC14a, cutting power to the micro. IC14a’s “set” input (pin 6) is tied to ground and its data input (pin 5) is pulled high. It is therefore switched on by a positive transition on clock input pin 3. The clock pin is driven by pushbutton S2 with an associated 47kΩ pull-down resistor, hence pressing S2 turns the micro power on. Similarly, pushing S3 turns the power off since this pulls the reset input (pin 4) high via a 2.2kΩ resistor and diode D4. IC14a is also reset initially by the 100nF capacitor from D4’s anode to +16V, so micro power is off when the unit is first switched on. IC14b, the other half of the dual flipflop IC, is used to indicate if an over-current trip occurs. When the output of comparator IC16a goes high, it not only resets IC14a but also sets IC14b via pin 8. This turns on red LED3 to indicate a fault. This LED can then be turned off using pushbutton S3 (power off) since this pulls its pin 10 reset input high. When the output of IC14a is high and Mosfet Q16a is on, supplying power to the micro, yellow LED2 is also lit. IC14a also drives the input of inverter stage IC12d, which enables clock signal multiplexers IC4 and IC5. DIP4 must also be on for the clock enable to be asserted as otherwise, pin 6 of IC12d remains low. Pin header CON5 can be used to monitor VCC externally and if necessary, provide an off-board micro power supply. Three-pin header LK2 selects whether the ICSP receives power at the same time as the micro or when the programming adaptor board is switched on. It is usually left in the position shown, with pins 2 and 3 shorted, selecting the former condition. LDO regulator REG3 derives 2.5V from VCCS (3.3V or 5V) when Q16a is on. This is required when programming PIC18LF2xJ5x micros. More to come Next month, we will provide the PCB overlay diagrams and the construction details. We’ll also detail the set up and describe how to use the SC Programming Adaptor Board. Issues Getting Dog-Eared? Keep your copies of SILICON CHIP safe, secure and always available with these handy binders REAL VALUE AT $14.95 PLUS P & P Available Aust, only. Price: $A14.95 plus $10 p&p per order (includes GST). Just fill in and mail the handy order form in this issue; or fax (02) 9939 2648; or call (02) 9939 3295 and quote your credit card number. siliconchip.com.au May 2012  39