Sunday, August 15, 2021

ATMega16 Push Button And 7-Segment Display

Overview

A button is one of the old style user to controller interface. It still useful in many low end control application. However some modern digital control system implement a button in software via a computer software GUI or a touch panel.



ATMega16 Push Button And 7-Segment Display
Running program on experiment board

ATMega16 Push Button And 7-Segment Display
Some tactile switches are examples of input button.

Most of many on-board button interface, a tactile switch is usually found. They are varied in size and package type.

Interfacing A Button to ATMega16

Using a digital input pin of ATMega16, interfacing and programming for the user input using a button is effortless.

The program test the button pressed using a high or a low logic level. It test whether the input changes its logic state.



Programming example

A simple programming example, the ATMega16 microcontroller keeps track of the input change from high to low. The microcontroller increase a counting variable whenever this happens.

ATMega16 Push Button And 7-Segment Display
Schematic Diagram

The 7-Segments display is just like the previous post. A tactile switch connects to PIND2. It creates a low logic level whenever it’s pressed. It’s normal high logic level doesn’t need an external resistor. The program turn PIND2 high in code.

In AVR GCC we test the present of a low logic level of the input by using the expression,

(PIND&0x04)==0

This expression return true if PIND2 equal to ‘0’ (low logic level).



An electro-mechanical switch creates noise which is called bouncing. It varies the input logic between high and low repeatedly for some milli-seconds. There exists many technique to eliminate this phenomenon. However, I use a timing delay about 250 mS to bypass it.

This embedded program example counts the input increment from 0 to 15 before it rolls back to 0.

The AVR GCC coding example lists below.

  1. /*
  2.  * btnSsdCa.c
  3.  *
  4.  * Created: 11/15/2020 8:40:33 PM
  5.  * Author : Admin
  6.  */
  7.  
  8. #include <avr/io.h>
  9.  
  10. #define F_CPU 16000000UL
  11. #include <util/delay.h>
  12.  
  13. int main(void)
  14. {
  15. //7-Segment data table
  16. unsigned char cAnode[16]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
  17. 0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
  18. //counting parameter
  19. unsigned char cnt=0;
  20. //Port C As Output
  21. DDRC=0xFF;
  22. //PIND2 As Input
  23. DDRD&=~(1<<2);
  24. //Set PIND2 High
  25. PORTD=(1<<2);
  26. while (1)
  27. {
  28. //Display the 7-Segments Data
  29. PORTC=cAnode[cnt];
  30. //Increase the counter
  31. if ((PIND&0x04)==0)
  32. {
  33. _delay_ms(250);
  34. cnt++;
  35. }
  36. if(cnt>15) cnt=0;
  37. }
  38. }

An input tactile switch is already mounted on board, connects to PIND2 for a dedicated purpose. It excepts the single-digit 7-Segments display that need external circuit connection.



ATMega16 Push Button And 7-Segment Display
This example program runs on my development board.

Click here to download this example program in zip file. See a video of this example on YouTube:

Saturday, August 14, 2021

DIY ISP Board for USBasp AVR programmer

 

Introduction

USBasp is an open-source low cost AVR In-System-Programming (ISP). On-line stores offer this programmer at a very low cost.

DIY ISP Board for USBasp AVR programmer
My DIY AVR ISP Adapter

 

DIY ISP Board for USBasp AVR programmer
Sample of USBasp programmer on Ali Express
Its programming header pin to AVR ISP pin on breadboard while prototyping. For convenience we must make another ISP board that hold AVR device for program uploading.
 



DIY ISP Board for USBasp AVR programmer
A 3D Visualization of AVR ISP socket for USBasp

Designing for AVR ISP Socket

I have been using most of AVR ATMega series from 8 to 40-pin counts DIP package in prototyping. One designed PCB could fit these AVR devices.

Schematic Design

Circuit design software make this schematic design fast and reliable with their rich of device libraries and detailed pins diagram.

DIY ISP Board for USBasp AVR programmer
Schematic Diagram

System doesn’t have its own power supply. It’s driven from ISP header. The header is a male 10-pin IDC socket.

A crystal clock X1 is optionally added targeting any AVR device that fused with crystal oscillator.

A 45kHz oscillator block created by NE555 timer IC that can be switch to XTAL1 pin of AVR device. It’s useful for AVR fuse recovery.



Circuit Design

Devices connection in schematic design creates a netlist that export to PCB design step. Most of devices symbol in schematic design have their own PCB footprint.

DIY ISP Board for USBasp AVR programmer
Printed Circuit Design View

This design requires about 17 on-board component counts. Final design is a double-sided PCB. However top layer made of around a dozen of copper tracks. 



DIY ISP Board for USBasp AVR programmer
Copper pattern of this circuit design

 
DIY ISP Board for USBasp AVR programmer
Top copper layer mirror

DIY ISP Board for USBasp AVR programmer
Components layer – mirror

PCB Fabrication



This circuit design is no simple as there are a lot of component counts, and their on-board interconnections. This double-sided PCB can become a single-sided PCB by replacing top copper with wire jumpers.

DIY ISP Board for USBasp AVR programmer
Finished and fully tested PCB assembling at component side

 
DIY ISP Board for USBasp AVR programmer
Copper side coated with clear acrylic vanish
I made this printed circuit by hand using toner-transfer-method. PCB fabrication, assembling, and testing was completed nearly one daytime.



Click here to download design file. For time saving and good quality of PCB we can order for PCB fabrication service. It’s more reliable and professional. We can preview this design using online using online Gerber view.

DIY ISP Board for USBasp AVR programmer
PCB panel view using online Gerber view at component side

DIY ISP Board for USBasp AVR programmer
PCB panel view using online Gerber view at copper side

Testing with USBasp Software



I tested this ISP adapter with USBasp programmer I made. I have only a little AVR chips for prototyping.

DIY ISP Board for USBasp AVR programmer
Detecting Atmega32 using USBasp

 

DIY ISP Board for USBasp AVR programmer
Detecting Atmega8 using USBasp


Friday, August 13, 2021

DIY Arduino Wire and Relay Shield

 

Introduction

Prototyping Arduino sketch in physical hardware requires only an Arduino board, breadboard, its related components, and its accessories. Hardware prototyping on breadboard doesn’t require any lead soldering, but it may have a risk in components burning, etc.

DIY Arduino Wire and Relay Shield
DIY Arduino Wire and Relay Shield

 

An Arduino shield is a ready-to-use electronics module that plug into an Arduino Single Board Computer (SBC) – for example a motor driver module, an Ethernet module. The are a vast majorities of Arduino module available at low cost.



DIY Shield for Arduino Uno

I have a few Arduino Uno SBC. Some discrete electronic components available in my own warehouse. I usually annoying with errors while circuit prototyping on breadboard. With a new version of PCB design, a template of Arduino shield designs were available.

Schematic Design

I putted two main categories of module on a single Arduino shield design – Wire and electro-mechanical relay.

Wire typically called Two-wire Serial Communication (TWI) devices. On this shield it contains a DS1307 Real Time Clock (RTC) and a serial EEPROM.

An SPDT electro-mechanical relay is additionally added on this shield due to the present of free space on its PCB.


D1 is an optional indicating LED to check the output frequency of square wave output from RTC.

There are two input output connectors for relay. It can be used for both DC and AC voltage.

Circuit Design

Proteus project wizard contains a design template for Arduino shield. We will select a template for Arduino Uno shield for ease of design.

DIY Arduino Wire and Relay Shield
A view of circuit design in EDA software



However I additionally draw the schematic in schematic design section before making the PCB design because the template is only presented as the skeleton of PCB.

Circuit Pattern

As it’s shown in the picture above, it seems to be a double sided PCB with a few top copper layer tracks. We can ignore the top copper track, and fabricate this design by hand with only the bottom copper layer. Toner-transfer-method is a first priority for most hobbyists and students.

DIY Arduino Wire and Relay Shield
Bottom copper layer for soldering

Top layer contain both top copper tracks and components legend.

DIY Arduino Wire and Relay Shield
Top layer for components placement

Completed DIY PCB



I made this prototype by hand using a simple toner-transfer-method.

DIY Arduino Wire and Relay Shield
Top layer components placement

Bottom copper was fine due to a good circuit protection during lamination to transfer toner to the copper sheet.

DIY Arduino Wire and Relay Shield
Bottom copper soldering layer



 Some long male header pins for Arduino shield is required for this DIY circuit board. Click here to download zip file of this design. Proteus version must be 8.9 or higher.

DIY PIC18F4550 USB Prototype Board

DIY PIC18F4550 USB Prototype Board
Prototype Board for PIC18F4550 and other 8-bit 40-Pin PIC Microcontroller Experiment Board for Hobbyists

Labels