Micro controller units are devices which contain a processing unit, programming and data memory and I/O. Early MCU's could not modify its program memory only the data memory. The program memory of present day MCU's can be modified with an in circuit programmer - ISP or ICSP - thru designated pins on the device or by the processor using special instructions.
A bootloader is firmware, usually written into upper memory, which is executed when the MCU is reset. Typically, on reset, the bootloader waits for data to be input on the serial port and if this does not happen in a few seconds the bootloader jumps to the previously loaded code. If the data does start flowing, it is checked for correct protocol and loaded into program memory. The Atmel ATmega and the Microchip 18F MCU's handle bootloaders in a similar way.
A bootloader PC application interfaces with the MCU using the serial port. Before using the pc app to download the hex code, the reset switch at the MCU must be pressed. This sequence can be simplified by the PC application first triggering the serial port's DTR signal which at the MCU is connected to the reset pin. On the Arduino this is called auto reset.
Friday, May 18, 2012
Sunday, May 13, 2012
Programming the Optiboot into the ATmega328
I have been using the PicKit2 and a ZIF socket to program the 18F series of MCU. This setup is inexpensive and handy. I would like to have a similar setup for use with the Atmel mcu's.
USBasp: The least expensive ATmega in circuit programmer, ISP, I have come across is the USBasp which is sold on many sites and all seem to be by different unknown manufacturers. The USBasp sold by HobbyKing for $4.50 had good reviews and a cable with both 10 pin and 6 pin connectors. The Arduino boards, as well as my designs, use a 6 pin ISP connector. I also located 28 pin, 0.3" ZIF sockets made by Textool, # 228-3341, which I cannot find in the Textool datasheets since it has been discontinued. I ordered and have received 2 sockets and they indeed have that number. Here are some sources for the USBasp:
EMS ISP Shield: Evil Magic Science makes a Arduino shield kit that contains a ZIF socket and can be used with the Arduino ISP sketch to program bootloaders into ATmega MCU's. Adafruit sells a similar kit. The bare pcb from the EMS kit, which is sold separately, could be used as a standalone ZIF board with the USBasp to do the same thing.
OptiLoader: This sketch, which can be found here, turns a Arduino board into a stand alone optiboot programmer. The sketch contains images of OptiBoot hex files for several ATmega devices. When the reset switch is pressed, OptiLoader looks at the attached ATmega device to determine what it is and then programs it with the correct OptiBoot. While doing this, sequence data is sent out the serial port which can be monitored with the Arduino IDE serial communication tool.
For a setup using solderless breadboards look here. My setup will use a modified Evil Mad Science ISP shield, purchased as a bare pcb, and an Arduino Duemilanove
AdaLoader: This sketch, which can be found here, is based on the OptiLoader, but uses LED's and a beeper as progress feed back. The AdaLoader sketch has only one bootloader image and the LadyAda site describes how to change the image. The AdaLoader uses LED's for PROG and ERROR connected to pins A0 and D8, respectively, and a beeper to indicate program completion at pin A3. To program the bootloader press reset after loading the ATmega into the ZIF socket assuming your using the ISP shield.
ArduinoISP: This sketch which is part of the Arduino IDE download and can be found in the Examples folder turns an Arduino board into and AVRISP programmer. The ArduinoISP uses LED's for PROG, ERROR and HEARTBEAT connected to pins D7, D8 and D9, respectively.
ArduinoISP2: This sketch which is available at LaydAda is based on the ArduinoISP sketch, but has been modified to work with Arduino IDE 1.0. The ArduinoISP2 uses LED's for PROG and ERROR using A0 and D8. A beeper connected to A3 signals program complete. To program the ATmega328P device, first, dowmload the ArduinoISP2 sketch to the Arduino, then using the IDE do Tools > Burn Bootloader > w/Arduino as ISP. The green LED will light indicating the bootloader is being loaded. When loading is complete the green light will go out and the IDE will show "Done burning bootloader".
EMS ISP Shield Modifications:
Changes
New ISP Loader Shield
USBasp: The least expensive ATmega in circuit programmer, ISP, I have come across is the USBasp which is sold on many sites and all seem to be by different unknown manufacturers. The USBasp sold by HobbyKing for $4.50 had good reviews and a cable with both 10 pin and 6 pin connectors. The Arduino boards, as well as my designs, use a 6 pin ISP connector. I also located 28 pin, 0.3" ZIF sockets made by Textool, # 228-3341, which I cannot find in the Textool datasheets since it has been discontinued. I ordered and have received 2 sockets and they indeed have that number. Here are some sources for the USBasp:
- HobbyKing of HK: USBasp programming device for Atmel processors
- XHeli: KK control board USBasp
- Fun4diy: USBasp kit
- ProtoStack: USBasp AVR Programmer
EMS ISP Shield: Evil Magic Science makes a Arduino shield kit that contains a ZIF socket and can be used with the Arduino ISP sketch to program bootloaders into ATmega MCU's. Adafruit sells a similar kit. The bare pcb from the EMS kit, which is sold separately, could be used as a standalone ZIF board with the USBasp to do the same thing.
OptiLoader: This sketch, which can be found here, turns a Arduino board into a stand alone optiboot programmer. The sketch contains images of OptiBoot hex files for several ATmega devices. When the reset switch is pressed, OptiLoader looks at the attached ATmega device to determine what it is and then programs it with the correct OptiBoot. While doing this, sequence data is sent out the serial port which can be monitored with the Arduino IDE serial communication tool.
For a setup using solderless breadboards look here. My setup will use a modified Evil Mad Science ISP shield, purchased as a bare pcb, and an Arduino Duemilanove
AdaLoader: This sketch, which can be found here, is based on the OptiLoader, but uses LED's and a beeper as progress feed back. The AdaLoader sketch has only one bootloader image and the LadyAda site describes how to change the image. The AdaLoader uses LED's for PROG and ERROR connected to pins A0 and D8, respectively, and a beeper to indicate program completion at pin A3. To program the bootloader press reset after loading the ATmega into the ZIF socket assuming your using the ISP shield.
ArduinoISP: This sketch which is part of the Arduino IDE download and can be found in the Examples folder turns an Arduino board into and AVRISP programmer. The ArduinoISP uses LED's for PROG, ERROR and HEARTBEAT connected to pins D7, D8 and D9, respectively.
ArduinoISP2: This sketch which is available at LaydAda is based on the ArduinoISP sketch, but has been modified to work with Arduino IDE 1.0. The ArduinoISP2 uses LED's for PROG and ERROR using A0 and D8. A beeper connected to A3 signals program complete. To program the ATmega328P device, first, dowmload the ArduinoISP2 sketch to the Arduino, then using the IDE do Tools > Burn Bootloader > w/Arduino as ISP. The green LED will light indicating the bootloader is being loaded. When loading is complete the green light will go out and the IDE will show "Done burning bootloader".
EMS ISP Shield Modifications:
Changes
- Cut land from reset switch and connect switch to Arduino Reset pin.
- Cut land from anode of Hello LED and connect to A0 pin.
- Add beeper and connect to pin A3.
New ISP Loader Shield
Project Objective: To design a shield which can be used with all of the above sketches.
Specification List:
Schmatic:
Problems with AutoReset: Normally, before a sketch is downloaded to the Arduino the serial port DTR signal triggers which cause a reset and the bootloader to execute. AVRdude when it connects to the Arduino board also triggers DTR on the serial port causing an Auto Reset.
Specification List:
- 28 pin ZIF socket
- Reset switch paralleling Arduino board reset switch
- Power switch for socket
- Both 6 and 10 pin ISP connectors with target power jumper
- LED's for PROG, ERROR and HEARTBEAT
- Beeper
- Serial LCD connector
![]() |
| ISPL Shield Rev A |
![]() |
| ISP Loader Shield Rev B |
Problems with AutoReset: Normally, before a sketch is downloaded to the Arduino the serial port DTR signal triggers which cause a reset and the bootloader to execute. AVRdude when it connects to the Arduino board also triggers DTR on the serial port causing an Auto Reset.
Still working on this. 6/6/12
Sunday, May 6, 2012
USB FTDI Breakout Problems
Since many of my projects use a USB FTDI breakout with a 6 pin output connector, I have been examining the available breakout boards. At the same time I have been examining the Optiboot loader for the Arduino which has added additional questions about these breakouts. To date, the only breakout I have purchased is the Basic USB FTDI breakout DEV 09716 from Sparkfun.
First, a study of the FTDI chip shows a pin, VCCIO, which control the interface signal levels for the chip. This pin should be tied to 5V, if driving a 5V devices such as the PIC 18F2520 and the ATmega328, or to 3.3V for 3.3Vdevices. If left unconnected, it defaults to 3.3V. On the Sparkfun it is left floating and a work-around is not easy; therefore, the DEV09716 produces 3.3V signals when driving a 5V ATmega or PIC device. Modern Device has found that with the Optiboot this can lead to download problems.
Though I do not intend to power my development boards from the USB, for those who do, you should noted that the USB can source a maximum of 500ma at 5V, and a maximum of 50ma at 3.3V from the internal LDO regulator on the FTDI chip. Considering the way I will use these breakouts, it would be more useful to tie the power pin of the breakout to VCCIO. Doing this would make sure the interface voltage of the FTDI chip matches the MCU being used; however, in this configuration the breakout could not power the PCB. From the schematic, the Amicus processor card uses this method, that is VCCIO of the FTDI chip tied to the VCC of the 18F25K20. Since the FTDI chip is on the Amicus PCB, the USB can power the board and, since they have an onboard 3.3V regulator, they do not have the current limit problems.
A final requirement for the USB breakout for use with my boards is that the output connector be mounted on the bottom of the breakout as with the Sparkfun DEV 09716.
Here are my recommendations for USB breakouts:
First, a study of the FTDI chip shows a pin, VCCIO, which control the interface signal levels for the chip. This pin should be tied to 5V, if driving a 5V devices such as the PIC 18F2520 and the ATmega328, or to 3.3V for 3.3Vdevices. If left unconnected, it defaults to 3.3V. On the Sparkfun it is left floating and a work-around is not easy; therefore, the DEV09716 produces 3.3V signals when driving a 5V ATmega or PIC device. Modern Device has found that with the Optiboot this can lead to download problems.
Though I do not intend to power my development boards from the USB, for those who do, you should noted that the USB can source a maximum of 500ma at 5V, and a maximum of 50ma at 3.3V from the internal LDO regulator on the FTDI chip. Considering the way I will use these breakouts, it would be more useful to tie the power pin of the breakout to VCCIO. Doing this would make sure the interface voltage of the FTDI chip matches the MCU being used; however, in this configuration the breakout could not power the PCB. From the schematic, the Amicus processor card uses this method, that is VCCIO of the FTDI chip tied to the VCC of the 18F25K20. Since the FTDI chip is on the Amicus PCB, the USB can power the board and, since they have an onboard 3.3V regulator, they do not have the current limit problems.
A final requirement for the USB breakout for use with my boards is that the output connector be mounted on the bottom of the breakout as with the Sparkfun DEV 09716.
Here are my recommendations for USB breakouts:
- Modern Device, BUB 1 @ $14.. This unit makes it possible to connect up just about any way you want. Because of this it is bigger than the competition. This unit has a poly fuse and a ferite filter.
- Modern Device, BUB 2 @ $14. Similar to Friend with addition of an on board 3.3V optional regulator. The output connector is right angle and is shipped unsoldered. Fused.
- Adafruit, USB Friend @ $14.75. For my uses this has all the jumpers, as solder bridges, that I need. No fuses or filters.
- DFRobot, DFR0065 @ $15.95 from Jameco. This seems to be alright but I have asked some question of DFRobot so we will see what their answers are. Poly fuse.
Monday, April 30, 2012
uLab 28 PIC
PROJECT OBJECTIVE:
A PIC 28 pin processor board for use with slbb's. The board plugs
into the slbb and incorporates an adjustable regulator for 5Vand
3.3V, a serial communication connector, ICSP, Picaxe and BasicAtom
interfaces.
INTRODUCTION:
This device was developed to expedite the setup of projects on a
solderless breadboards for 28 pin PIC processors including Picaxe and
BasicAtom.
Power:
A single adjustable LDO regulator provides 5V and 3.3V jumper
selectable, switchable power. The switch in its off position shorts
the circuitry to ground for a clean shutdown. A green LED indicates
power on.
Programming:
The processor can be programmed in-circuit using the Tiny bootloader
with the communication port or ICSP . When using the ICSP, the
programmer, such as the PicKit2, should not be used to power the
processor because of the shorting switch. If a Picaxe or BasicAtom
part is being used, then programming is by the appropriate comm
connector.
Communication:
The communication interface is not provided on-board, but requires
and appropriate breakout device for RS232 or USB to TTL conversion. A
RS232 SMD breakout board is included as one of our projects, with pcb
and kit available for those using PC com ports. The FTDI USB to TTL
cable available from Mouser will work with Tiny bootloader which
requires RTS on pin 6 for auto-bootloading. (We believe that Amicus
requires DTR on pin 6.)
Testing:
A single red LED is provided for quick setup testing. A single
momentary switch is also provided.
FEATURES:
- Header for plugging the I/O ports to a slbb
- Each port pin marked to ease jumper connection
- Mating pins to the slbb power busses
- 3.3V and 5V selectable power with switch
- Picaxe 28X and BasicAtom Nano programming ports
- 28 pin PIC processors: 16F886, 18F2420, 18F25K20, 18F25K22, etc with Tiny bootloader
- Power LED
- Single LED tied to B0 and switch to B1 for testing
- Connector bank for easy connection of sensors to ADC's
DIMENSIONS:
2 inch by 3 inches
SCHEMATIC DIAGRAM:
PICTURE:
BOM:
| Count | Label-Value | Designation(s) | Mouser PN | Manf |
| 1 | 470uf 25V | C1 | UHE1E471MPD | Nichicon |
| 1 | 22uf@16V | C2 | UVR1C220MDD | Nichicon |
| 2 | C10 C9 | |||
| 1 | .1uf | C3 C4 C5 C8 C11 C12 | C322C104K5RSTA | Kemet |
| 2 | 22pf | C6 C7 | 140-50N2-220J-RC | Xicon |
| 1 | 1N5817 | D1 | 1N5817 | Fairchild |
| 1 | LED T1 GRN | D2 | HLMP1790 | Everlight |
| 1 | BAT85 | D3 | BAT85 | Vishay |
| 1 | LED T1 RED | D4 | HLMP1700 | Everlight |
| 1 | 1N4148 | D5 | 1N4148 | Fairchild |
| 4 | HEADS6 | J1 J2 J3 J8 | 3M | |
| 1 | HEADS24 | J4 | 3M | |
| 1 | HEADRAS6 | J5 J6 | 3M | |
| 1 | 620454-3 | J7 | 640456-3 | AMP |
| 1 | FHEADS2 | JC1 | 3M | |
| 5 | HEADS2 | JP1 JP2 JP4 JP5 JP6 | 3M | |
| 1 | HEADS3 | JP3 | 3M | |
| 1 | PJ102A | P1 | CP-102A-ND | Cui (Digikey) |
| 5 | 10K | R1 R10 R2 R6 R9 | 270-10K-RC | Xicon |
| 1 | 360R 1% | R11 | 299-360-RC | Xicon |
| 1 | 432R 1% | R12 | 299-432-RC | Xicon |
| 1 | 120R 1% | R13 | 299-120-RC | Xicon |
| 1 | 22k | R3 | 270-22K-RC | Xicon |
| 2 | 1K5 | R4 R8 | 270-1.5K-RC | Xicon |
| 1 | 470R | R5 | 270-470-RC | Xicon |
| 1 | 180R | R7 | 270-180-RC | Xicon |
| 1 | Switch Slide | S1 | 103-12100-EV | Mountain Switch |
| 1 | SW 3.5x6mm RED | S2 | TS4311T2601-EV | Mountain Switch |
| 1 | SW 3.5x6mm BLK | S3 | TS4311T1601-EV | Mountain Switch |
| 1 | Pic 18F | U1 | 18F25K22I/SP | Microchip |
| 1 | Reg. LDO Adj | U2 | NCP1117DTA | ON Semi |
| 1 | XTAL 16mhz | Y1 | 16 mhz | |
| 1 | Dip Socket 28 pin | SK1 | 4828-3004-CP | 3M |
PCB LAYOUT: (if required)
Wednesday, April 25, 2012
Picduino, Pic on the Arduino Form Factor
PROJECT OBJECTIVE:
Replace the AVR processor on the Arduino form factor with a 28 pin
18F PIC processor. Add both an EEPROM and RTC to the design. Use thru
hole, including DIP parts, to facilitate assemble.
FEATURES:
- 18F, 28 pin PIC processor (16F optional)
- Tiny bootloader with auto-bootloading (DS30 coming)
- Arduino pcb form factor
- Serial communication using breakout boards
- Stackable connectors with Arduino compatible pinout
- Dual LDO regulators for 3.3V and 5V.
- Power switch, 300ma
- Jumper for comm port power
- Onboard I2C RTC and EEPROM
- ICSP connector at front
- Reset switch accessible at front
- Testing LED on B0 at front
INTRODUCTION:
Initially, the18F2520 will be used since there is an available Tiny
bootloader that we have been using with good results. Presently, we are testing the 18F25K22 with the DS30 bootloader.
This design uses
the Arduino physical stacking connectors, without change, except for
some signal assignments. The USB circuit which is incorporated on the
Arduino has not been incorporated on the Picduino, but will be
contained on a breakout board allowing both RS232 and USB serial
communication. The RS232 breakout will be available with the initial
project and for USB communication the Sparkfun DEV 09716 will be used. This will provide the same USB functionality as the Arduino
with the exception of powering the Picduino from the USB port.
The 18F2520,
18F25K22 and 18F25K20 use 5V and 3.3V respectively; therefore, dual
LDO regulators have been provided. Dual regulators, also seem
reasonable, since there may be shields requiring both voltages. A
switch is used to apply power to the board.
Since the intended
use for the Picduino is as a base unit for the Rainwater Level
Monitor project, an RTC and EEPROM were incorporated on the main Picduino PCB. Because the
Picduino can operate at 3.3V the RTC, DS1307 can't be used and has
been replaced by the PCF8563 in the design
For software
development, several compilers can be used including: OS Basic,
MikroBasic Pro, Swordfish and Proton. If you use the 18F25K20 or 18F25K22, then
the free Amicus compiler can be used. With the latest updates, PicKit2 will program the
18F25K22, see Tips and Tricks. The18F25K22 is also supported by
MPLAB.
The “C”
compiler used by Arduino can create compiled modules and then linked
from libraries using an Include directive. Both MBP and SF can do
this, but PicBasic Pro, Proton Basic, OS Basic and Amicus can't.
This feature of the AVR-GCC compiler is one of the reasons that the
AVR processor was picked for Arduino and why the Arduino platform is
so successful. Our intention is to develop code with Swordfish and OS Basic.
As an aside, the
method of Arduino development is similar to our method described in
this site. Compile the code, download it, examine its behavior, then
make adjustments to the code and try again. There are code developers
out there who use the AVR-GCC to create modules that the uninitiated
can use. Most of the hard work is done by those developers. For
example, writing code to generate the model train DCC signal is not
simple because of the timings involved, but I am sure some developer
is out there building a DCC module.
Note 1: The
Arduino uses DTR of RS232 to reset the processor for an autoboot. The
FTDI cable brings out RTS on pin 6 not DTR so it will not work in
autoboot mode. Sparkfun sells a USB breakout board that will work
(DEV-09716).
DIMENSIONS:
W: 2.7 in, L: 1.9
in, H: .5 in
SCHEMATIC DIAGRAM:
PICTURE:
BILL of MATERIALS:
PCB LAYOUT:
Monday, April 23, 2012
Using a LCD Terminal for MCU Software Debugging
One of the advantages of an in circuit debugger, ICD, is the ability to monitor variables. If you are using a bootloader for development an LCD terminal can be used for that purpose. Connect the LCD terminal to an unused pin on the MCU and output the variable information using software UART code that most compilers provide. Setting a break or tight loop right after the variable output is often necessary. In time I will provide some examples of this method below.
Sunday, April 22, 2012
LCD Terminal, the GMterm II
Project GMterm II
PROJECT OBJECTIVE:
To develop a serial LCD terminal written in OS Basic that will
respond to the PH Anderson command set. To design a pcb for the project.
INTRODUCTION:
This project started out as an attempt to produce firmware for the 16F886 that would
respond to the command set of the PH Anderson serial LCD products
sold as programmed 16F628 chips, except with all code written in
Basic.. Andersons code was written in assembly language, used an
interrupt driven buffer on the serial input and provided RS232 and
TTL inputs. As mentioned elsewhere in this site, I used PHA's device
to monitor variables during code development and .now I use the GMterm 2.
GMterm has all
code written in OS Basic and responds to all of the PHA's commands, except for big numbers. It uses a interrupt driven barrel buffer for the input serial data stream. A pcb has also been designed to house
the GMterm chip and, though, the initial design used the 16F886, the
pcb can also use the 18F2420, 18F2520 and the 18F25K22. Since the
code is written in Basic, conversion to the other MCU's is easy.
Since the 28 pin
devices have additional I/O, other capabilities could be added to the
PHA design, such as, four selectable baude rates, command
controllable contrast and serial interface daughter boards.
FEATURES:
- LCD: 1x8 to 4x40
- Backlight control, PWM
- Contrast control: digital or analog potentiometer.
- I/O, direct TTL and RS232
- Daughter board for RS232, RS485 ( full and half duplex) and USB
- I2C with branch, 16 address, 6 meters max.( not implemented)
- USART select: 8 or 9 bit
- baude: 2400, 9600, 19.2k, 38.4k
- GPIO
- Command Set: Basic and extended
- Tiny Bootloader
- MCU: 16F886, 18F2420, 18F2520 and 18F25K22
- Requires external regulated power.
DIMENSIONS:
W 1.5 inch, L 2.8
inch
PICTURE:
SCHEMATIC:
SCHEMATIC:
SLBB DEVELOPMENT SETUP:
Intro: The solderless breadboard, slbb, setup uses the uLab28 PIC and is pictured below. This setup implements part of the circuit
diagram: 16F886, LCD, contrast pot and a speaker. If you do not have a uLab28 then the entire circuit can be wired on the slbb. You will also need to provide +5V to the circuit from a separate power supply or a regulator wired on the slbb.
What's Needed
- SLBB with 830 or 1660 contacts
- Wart: 6 VDC @ 500ma unregulated
- Addon: PWR-1 or (7805 + parts)
- Addon:RS232 ( ST232CN + parts)
- Microchip 16F886 with Tiny bootloader
- 20x4 LCD Vishay L020N4AYYHET or equivalent
- Digital Pot.CAT5113LI-10-G
- Oshonsoft PicSimIde Basic compiler
- Tiny Bootloader
- PC with a RS232 port
The LCD used in our setup
has a SIP connector at the top of the display similar to the Vishay
part above. The sip can be plugged directly into the slbb or use
adapters with a ribbon cable. The Simple Menu project uses adapters.
If a 7805 regulator will
be used in your setup, then a 7.5VDC wart may be needed. This can be
determined by checking the voltage drop across the regulator. The
backlight on the LCD draws the greater power, about 200ma. If you are
having overheating, change the backlighting level or turn it off.
Step 1) Wire a basic
setup including: processor and RS232 interface. Connect a LED with
resistor from B0 to ground. The uLab28-PIC has all of this on-board.
Step2) Compile a LED
blink routine and download to make sure bootloader and hardware are
working properly. There is a blink routine in zip file.
Step3) Complete basic
SLCD wiring while referring to Basic circuit diagram. See zip file.
PDF DATASHEETS:
LINKS:
Tiny Bootloader
Oshonsoft
LISTING:
PCB LAYOUT:
Subscribe to:
Posts (Atom)







