Project around the ATMEGA 1284P

This is a working draft.

Contents

Project around the ATMEGA 1284P 2

The ATMEGA 328P and 1284P processor 2

Needs for the project 5

Install the libraries in the Arduino IDE 5

The PCB 6

Burning a bootloader on the 1284P 7

Use a FTDI to program the chip 9

Turning on and off LED’s 10

Measuring the Crystal frequency 10

Turn a 5V PWM signal to a 12V PWM signal 11

Use the DCF77 time receiver 12

Using a FM-radio to receive time from the RDS signal and tune to a station 15

Using a GPS to receive time and position on the globe 15

Use the Bluetooth HC-05 and BT-BLE modules to send and receive messages 15

Communicate with Android, Windows and Apple devices 15

Communicate with a LCD display 15

Communicate with a pix? by pix? 12864 OLED display 15

Amplify a 5V signal to a 12V signal 15

Reduce a 5V signal to a 3.3 V signal 15

Use buttons 15

Use a rotary 15

Adjust some 1284P features 15

Some knowhow of the 1284P 15

Project around the ATMEGA 1284P

For people born in the 50-ties of the previous century the Arduino brings back hobbies from their youth. When I was around 20 the first calculators became affordable. Later the Commodore 64, Acorn BBC B computer and then MS-DOS on IBM-compatible PC were the standard. I learned programming in Lattice C and couple device to the PC. For the single programmer like me C-programming ended when C++ compilers were designed to work with projects. Borland C V4 was for me the last and almost perfect IDE. After W95 and the connection to internet computers became more secure. Now with Windows 10 and IPad’s, the systems were consumable and closed devices. You need assistance from external companies to connect their closed devices to your computer system and dozens of people to open network ports, allow access to the completed closed PC.

The Arduino and Raspberry computers are therefore not surprisingly extremely interesting for people just in or on the brink of their retirement and a lot of time to spent and learn again.

I chose the Arduino and used the Word clock as a project to start to learn simple electronics and use my programming skills to hobby again.

The Arduino offers a simple IDE (integrated development environment) and C as programming language. Raspberry’s are using that difficult to operate UNIX and is far too powerful for the smaller projects.

The ATMEGA1284P processor from ATMEL has more program memory than the ATMEGA328; 128K instead of 32K memory. Especially when several libraries are used in the project, WS2812 RGB LED’s are added, 32K of memory becomes tight. For these purposes Arduino developed the Arduino Mega around the ATMEGA2560 chip. But for the amateur electronic this is troublesome because this is a SMD chip and difficult to solder. The ATMEGA1284P is a large 40 pin chip that can be easily incorporated in a self-made PCB. This project is an enhancement of the ATMEGA328 version of the Word clock PCB.

During the evolution of software and hardware around a Word clock several input and output possibilities were required. That is a clock module, bit shift registers to control LEDS or relays at a higher voltage level than 5V, Bluetooth connection, DCF77, FM-radio and GPS receivers to adjust the time to atomic time clock transmitters. Burning the chip on the PCB with a FTDI connection to a PC, working at voltage levels of 3.3V, 5V and 12V and pulse width modulation to adjust the LED intensity. Also working with RGB WS2812 LED’s was one of the needs.

I realised that the designed board became a universal board with large and easy to solder DIP ATMEGA 328 or ATMEGA 1284P processor as the base.

The source code is written as one source. With the use of #define’s the use of modules can be turned on or off. The program is tested and can be used with ATMEGA328 chip, an Arduino UNO, Arduino Nano or an ATMEGA1284P. Programming with the 1284P has some quirks that had to be written down and here is the article ‘How to Do’ this.

The ATMEGA 328P and 1284P processor

ATMEL produces many processors with many possibilities. The ATMEGA 328P processor is used in the Arduino Uno and very popular. 328 stand for 32 KB memory 8 bits addressing. The 1284P has 128K memory and also 8 bits addressing. The P stands for PicoPower. In this article we use the P versions of the chip. The –PU stands for PDIP package that are the dual-line 28 (328) or 40 pin (1284) chips.

So, when looking for the processors; buy the 328P-PU or 1284P-PU chips.

Beside the memory size of the chip there are also differences in the amount of pins on the chip, 28 versus 40 and therefor also the number of analogue and digital ports.

The other characteristics of the processors are comparable. Both processors operate at voltages between 1.8V and 5.5V. The low voltage of 1.8V can be used when oscillators between 0 and 4 MHz are used. The chip contains an internal oscillator that runs at 8 MHz. We will use an external oscillator of 16 MHz. This should be used after burning the bootloader in the chip. The bootloader supplied with the Arduino IDE’s for this chip runs at 16 MHz and needs a working voltage between 4.5V and 5.5V to run at this speed.

But one can use these chips for low power consumption projects because the chip also has many sleep modes possibilities.

Features of the ATMEGA processors noted on their datasheets

1284P / 328P
• High-performance, Low-power AVR® 8-bit Microcontroller
• Advanced RISC Architecture
– 131 Powerful Instructions – Most Single-clock Cycle Execution
– 32 x 8 General Purpose Working Registers
– Fully Static Operation
– Up to 20 MIPS Throughput at 20 MHz
– On-chip 2-cycle Multiplier
• Nonvolatile Program and Data Memories
– 128K Bytes of In-System Self-Programmable Flash
Endurance: 10,000 Write/Erase Cycles
– Optional Boot Code Section with Independent Lock Bits
In-System Programming by On-chip Boot Program
True Read-While-Write Operation
– 4K Bytes EEPROM
Endurance: 100,000 Write/Erase Cycles
– 16K Bytes Internal SRAM
– Programming Lock for Software Security
• JTAG (IEEE std. 1149.1 Compliant) Interface
– Boundary-scan Capabilities According to the JTAG Standard
– Extensive On-chip Debug Support
– Programming of Flash, EEPROM, Fuses, and Lock Bits through the JTAG Interface
• Peripheral Features
– Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes
– Two 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture
Mode
– Real Time Counter with Separate Oscillator
– Six PWM Channels
– 8-channel, 10-bit ADC
Differential mode with selectable gain at 1x, 10x or 200x
– Byte-oriented Two-wire Serial Interface
– Two Programmable Serial USART
– Master/Slave SPI Serial Interface
– Programmable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analog Comparator
– Interrupt and Wake-up on Pin Change
• Special Microcontroller Features
– Power-on Reset and Programmable Brown-out Detection
– Internal Calibrated RC Oscillator
– External and Internal Interrupt Sources
– Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby
and Extended Standby
• I/O and Packages
– 32 Programmable I/O Lines
– 40-pin PDIP, 44-lead TQFP, and 44-pad QFN/MLF
• Operating Voltages
– 1.8 - 5.5V for ATmega1284P
• Speed Grades
– 0 - 4 MHz @ 1.8 - 5.5V
– 0 - 10 MHz @ 2.7 - 5.5V
– 0 - 20 MHz @ 4.5 - 5.5V
• Power Consumption at 1 MHz, 1.8V, 25°C
– Active: 0.4 mA
– Power-down Mode: 0.1 μA
– Power-save Mode: 0.7 μA (Including 32 kHz RTC) / • High-performance, Low-power AVR® 8-bit Microcontroller
• Advanced RISC Architecture
̶ 131 Powerful Instructions – Most Single Clock Cycle Execution
̶ 32 x 8 General Purpose Working Registers
̶ Fully Static Operation
̶ Up to 20 MIPS Throughput at 20MHz
̶ On-chip 2-cycle Multiplier
•High Endurance Non-volatile Memory Segments
̶ 32KBytes of In-System Self-Programmable Flash program memory
̶ 1KBytes EEPROM
̶ 2KBytes Internal SRAM
Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
̶- Data retention: 20 years at 85C/100 years at 25C(1)
̶ Optional Boot Code Section with Independent Lock Bits
̶ In-System Programming by On-chip Boot Program
̶True Read-While-Write Operation
̶ Programming Lock for Software Security
-Atmel® QTouch® library support
̶ Capacitive touch buttons, sliders and wheels
̶ QTouch and QMatrix® acquisition
̶ Up to 64 sense channels
• Peripheral Features
̶ Two 8-bit Timer/Counters with Separate Prescaler and Compare Mode
̶ One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and
Capture Mode
̶ Real Time Counter with Separate Oscillator
̶ Six PWM Channels
̶ 8-channel 10-bit ADC in TQFP and QFN/MLF package
- Temperature Measurement
̶ 6-channel 10-bit ADC in PDIP Package
̶ Temperature Measurement
̶ Programmable Serial USART
̶ Master/Slave SPI Serial Interface
̶ Byte-oriented 2-wire Serial Interface (Philips I2C compatible)
̶ Programmable Watchdog Timer with Separate On-chip Oscillator
̶ On-chip Analog Comparator
̶ Interrupt and Wake-up on Pin Change
̶ Power-on Reset and Programmable Brown-out Detection
̶ Internal Calibrated Oscillator
̶ External and Internal Interrupt Sources
̶ Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby, and Extended Standby
• I/O and Packages
̶ 23 Programmable I/O Lines
̶ 28-pin PDIP, 32-lead TQFP, 28-pad QFN/MLF and 32-pad QFN/MLF
• Operating Voltage:
̶ 1.8 - 5.5V
Temperature Range:̶ -40C to 85C
• Speed Grade:
̶ 0 - - 5.5V,
0 - - 5.5.V,
0 - 20MHz @ 4.5 - 5.5V
• Power Consumption at 1MHz, 1.8V, 25C
̶ Active Mode: 0.2mA
̶ Power-down Mode: 0.1μA
̶ Power-save Mode: 0.75μA (Including 32kHz RTC)

Needs for the project

As written before the project is built around a word clock. This clock drives 23 LEDs strips to make up the words that light up in matrix of letters to tell the time. Like: It was “five past three”
Here the text display the words is Dutch:
“Het was half zes”. That translates to:
It was half past five.
This clock uses Shift registers combined with a Darlington transistor array IC to switch from 5V to 12V to turn on or off LED strips voltage,
Bluetooth connection to set time and turn on- off features, a DS3231 clock module with I2C connection, FTDI connection to program the chip, rotary or button control, RDS time receiver from an RDA5807 FM-radio module and a LCD or OLED display connection. To make the word clock with RGB colour LEDs instead of white LED strips, WS2812 RGB LED’s were used.
All together a project that uses many techniques and a lot of research.
The project is built around the standard ATMEGA 328 chip with 32K memory or the 1284 processor chip with 128K memory.

The programming environment from Arduino: Download

IDE 1.6.11 of higher from: https://www.arduino.cc/en/Main/Software

Libraries: Download

https://github.com/mcudude/MightyCore Library for the 1284P board

https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library LiquidCrystal_I2C

All other used libraries are Arduino standard libraries.

Install the libraries in the Arduino IDE

If everything is installed from the Arduino IDE (Open from the IDE menu: Sketchà Include library à

Manage libraries) you will see the following directories in your library folder. The library folder is stored between you script folders in the Arduino folder in your Documents folder

29/07/2016 21:38 <DIR> DCF77

29/07/2016 22:59 <DIR> Encoder

29/07/2016 22:59 <DIR> FastLED

02/08/2016 13:16 <DIR> NewliquidCrystal

29/07/2016 22:59 <DIR> OneWire

29/07/2016 22:59 <DIR> RTClib

29/07/2016 22:59 <DIR> Time

#include <Wire.h>

#include <LCD.h>

#include <LiquidCrystal_I2C.h>

#include <RTClib.h>

#include <EEPROM.h>

#include <SoftwareSerial.h>

#include <Encoder.h>

#include "DCF77.h"

#include "TimeLib.h"

The PCB

The 1284P PCB (printed circuit board) is not essential. You can wire and solder the project up yourself. The project will be split in project parts and every part can work on itself with the ATMEGA1284P or 328P processor chip.

I use Fritzing to design my PCB. Download the Fritzing design program here: http://fritzing.org/download/

The Fritzing file of this PCB can be found here:

https://ednieuw.home.xs4all.nl/Woordklok/ATMEGA1280P_Project/Woordklok1284PV10.zip

Burning a bootloader on the 1284P

When processor chips are bought they are often without bootloader and then this must be installed on it.

The bootloader is a small program and during burning the bootloader also different settings (fuses) are set for the chip. Something like the bios in PC’s but then as a program. After power up or a reset of the processor the bootloader starts and listen to the RX and TX pins for a short time. In that time a program can be uploaded in the processor and started. It is possible to burn a program directly in the chip without a bootloader to spare approximately 1K of memory. For me that is too much fuss. As can be seen later using the bootloader makes life easier and the chip easy to reprogram.

For fuses and lock bits see: http://www.engbedded.com/fusecalc

There are 8 bits in the low fuse byte. These 8 bits are explained here:

•Bit-7: CKDIV8: When set divides the clock speed by 8

•Bit-6: CKOUT: When set clock pulses are output on PB0 (Pin 14)

•Bit-5: SUT1: Startup time delay

•Bit-4: SUT0: Startup time delay