Ads

Get STM32 tutorial using HAL at $10 for a limited time!

Sunday, August 14, 2016

ESP8266 WiFi Module Tutorial 3 - WiFi Station Mode and TCP Client

In the previous tutorial, we have seen how to setup the ESP-01 module as an access point and running a TCP server on it. In this tutorial, I will explain how to setup the ESP module as a station (WiFi device) and connects to an existing access point. The ESP module is configured as a TCP client, so it can connect to any TCP server. This is the block diagram that explain the system in this tutorial.


In this system, I will setup a PC as a WiFi soft access point (using Connectify software). The PC also runs a TCP server on port 23 using Hercules TCP terminal. The ESP module which acts as a WiFi station can connect to the PC access point. The ESP module which also acts as a TCP client can make a connection to the TCP server on the PC. After the connection is created, we can exchange data with the server. Serial to USB converter and serial terminal (Hercules) is used for controlling the ESP module.

Saturday, August 13, 2016

ESP8266 WiFi Module Tutorial 2 - WiFi Access Point Mode and TCP Server

In the previous tutorial, we have seen how to make a circuit for the ESP-01 module and we also test the module using AT command. In this tutorial, I will explain how to setup ESP-01 module as an access point and also running a TCP server on it. This is the block diagram that explain the system in this tutorial.


We setup the ESP module by using serial to USB converter and serial terminal software (Hercules). The ESP module is set as an access point and also runs a TCP server on port 23, so any WiFi device such as smartphones or PCs can connects to this access point. We can use TCP client terminal application on the smartphones or PCs for making a connection to the TCP server on ESP module. After the connection is created, we can exchange data with the server.

Friday, August 12, 2016

ESP8266 WiFi Module Tutorial 1 - Basic Circuit Testing

ESP8266 is a low-cost SoC (System on Chip) with capabilities for WiFi communication. This SoC contains a full TCP/IP stack and a microcontroller. The CPU in this SoC is a 32-bit RISC CPU: Tensilica Xtensa LX106 running at 80MHz. The WiFi is IEEE 802.11 b/g/n standard and also support WEP or WPA/WPA2 authentication. There are also several peripherals in this SoC: GPIO, SPI, I2C, I2S, UART, and ADC.


There is several WiFi modules that use this SoC. One of these modules is ESP-01 module. This module is manufactured by AI-Thinker. Actually there is other modules that manufactured by this company. The modules are labeled from ESP-01 through ESP-14. To work with this module, we need a serial TTL to USB converter and 3.3 volt power supply. The GPIO pin of this SoC is not 5V tolerant, so you need a voltage level shifter circuit if you want to connect this module to a 5V GPIO.


Thursday, August 11, 2016

Verilog Tutorial 5 - ModelSim - Simplified Floating Point and Signed Integer Conversion Circuit

The floating point format is utilized for representing a real number (number with a fractional component). Integer is a number without a fractional component. For example, 0, -2, and 168  are integers, while 12.25, 1/3, and π are real numbers.

In this tutorial, I have implemented a circuit for conversion between simplified floating point and signed integer number. The floating point format for this circuit is 13-bit like in the previous tutorial. The integer is in the 8-bit sign magnitude format. In the sign magnitude format, the MSB is a sign bit, while the other bits is the magnitude. For example, 100000012 is -110 and 000000012 is 110.


Verilog Tutorial 4 - ModelSim - Simplified Floating Point Greater Than Circuit

Real numbers in computer memory can be represented using fixed point or floating point format. For example, 12.2510 in 8-bit fixed point format will be 1100.01002. Actually, in the register, the value is only 1100010010. The radix point (binary point) is an implicit scaling factor which is 2-4. This scaling factor is the same for all values of the same type, and does not change during computation. In floating point format, 12.25 will be represented as 1.225 * 101 (in decimal). Floating point format can be thought of as a kind of scientific notation. The scaling factor in the floating point format is not fixed and can change during computation, so the range in floating point format is much larger than signed integer format. Detailed explanation of fixed point and floating point format is beyond the scope of this tutorial.

In this tutorial, I have implemented a greater than circuit for simplified floating point number. This circuit compares two simplified floating point number and assert output, gt, only when the first number is larger than the second number. Floating point number in this circuit is not conform to the IEEE 754 standard, hence this format is called simplified floating number.


Tuesday, July 19, 2016

Verilog Tutorial 3 - ModelSim - BCD Incrementor

Binary Coded Decimal (BCD) is a class of binary encoding of decimal numbers where each decimal digit is represented by a fixed number of bits, usually four or eight[1]. BCD is also called "8421" encoding. This is the truth table of BCD encoding, where each decimal digits is represented by its corresponding 4-bit binary value:


For example, 16810 (101010002) is represented as "0001 0110 1000" in BCD format. In this tutorial, I will implementing a digital circuit for adds 1 to a number in BCD format. The BCD format is three-digit decimal number (12-bit). For example, after incrementing, "0010 0101 1001" (25910) becomes "0010 0110 0000" (26010).

This is the top level schematic for three-digit BCD incrementor. This circuit is actually consist of three 4-bit incrementor module. 4-bit incrementor has input signal of BCD number and output signal of incremented BCD number. There is also a carry output signal that give indication when an incremented BCD number rollover (from 910 (10012) to 010 (00002)). In the three-digit incrementor circuit, this carry signal is used for give a signal to the next 4-bit incrementor module to increment the digit.

Sunday, July 17, 2016

Verilog Tutorial 2 - ModelSim - Dual Priority Encoder

A priority encoder is a circuit or algorithm that compresses multiple binary inputs into a smaller number of outputs[1]. In priority encoder, if two or more inputs are given at the same time, the input having the highest priority will take precedence. This is the four-request priority encoder truth table from FPGA Prototyping by Verilog Example book by Pong P. Chu.


You can learn the code implementation of that priority encoder from that book. In this tutorial, I will implement a dual priority encoder from suggested experiment on chapter 3 of this book. A dual priority encoder returns the code of the highest and second-highest priority request. The input is 12-bit signal and the outputs are the first and second priority codes, which are 4-bit binary codes of the highest and second-highest priority request.

Saturday, July 16, 2016

Verilog Tutorial 1 - ModelSim - Multifunction Barrel Shifter

A barrel shifter is a digital circuit that can shift a data word by a specified number of bits without use of any sequential logic, only pure combinational logic[1]. There are 3 type of bitwise shift operation: logical shift, arithmetic shift, and circular shift (rotate). We can shift the data to the left as well as to the right. The barrel shifter in this tutorial is a multifunction barrel shifter that can perform left or right circular shift. The basic barrel shifter in this tutorial is based on this book: FPGA Prototyping by Verilog Example by Pong P. Chu. You can also learn the basic of Verilog language from this book.

The multifunction barrel shifter in this tutorial is actually a suggested experiment from chapter 3 of the book. There are 2 design that will be implemented in this tutorial. The first design is using 1 rotate-left circuit, 1 rotate-right circuit, and one 2-to-1 multiplexer to select the desired result. The top level schematic of the first design is like this:


The second design is implemented using 1 rotate-left shifter with pre- and post- reversing circuit. The reversing circuit either pass the original input or reverses the input bitwise. For example, if the input is a7,a6,a5,a4,a3,a2,a1,a0 then the reversed result become a0,a1,a2,a3,a4,a5,a6,a7. The top level schematic of the second design is like this:

Friday, July 1, 2016

ARM Cortex-M3 (STM32F103) Tutorial - Incremental Rotary Encoder

Rotary encoder can be used for several application such as digital volume control, DC motor position sensor, etc. Rotary encoder is an electro-mechanical device that converts the angular position to an analog or digital code.


There are two type of rotary encoder: absolute and incremental. Absolute rotary encoder produce unique digital code for each distinct angle of the shaft. Incremental rotary encoder produce two square waves usually in quadrature output (channel A and B). The quadrature means that the output pulses of channel A and B are 90 degree out of phase.

Thursday, June 23, 2016

ARM Cortex-M3 (STM32F103) Project - 16 Point FFT Audio Spectrum Analyzer

This project is the application of FFT algorithm from my previous post. I made an audio spectrum analyzer project using ARM Cortex-M3 (STM32F013C8) and LED matrix 8x8. I used 16 point FFT. 16 point FFT will produce 16 point frequency spectrum. I only display the frequency spectrum from index 1 to 8 on LED matrix 8x8. Index 0 of frequency spectrum (DC signal) is not displayed. Index 9 to 15 of frequency spectrum (symmetrical frequency) is also not displayed.


My audio sampling rate is 35.15kHz, but the frequency sampling of FFT sample is 35.15kHz/2=17.5kHz. So, the maximum frequency domain signals that can be displayed is up to 8.75kHz (Nyquist's theorem) and the resolution is 8.75kHz/81kHz.

Wednesday, June 22, 2016

Complex DFT and FFT Algorithm Implementation Using C++ Programming Language

All four types of Fourier Transform family can be carried out with either real number or complex number. In my previous post, I shared how to implement real DFT algorithm using C++. In this post, I will implement the complex number version of DFT algorithm using C++. After that, I will also implement the Fast Fourier Transform (FFT) algorithm. FFT is another method for calculating the DFT. While it produces the same result as the DFT algorithm, it is incredibly more efficient, often reducing the computation time by hundreds. The algorithm that I use in this post is based on The Scientist and Engineer's Guide to Digital Signal Processing book. This book is very good for beginner to learn DSP.

The complex DFT transforms two N point time domain signals into two N point frequency domain signals. The two time domain signals are called the real part and the imaginary part, just as are the frequency domain signals. You can calculate the real DFT using complex DFT by move the N point signal into the real part of the complex DFT's time domain, then set all of the samples in the imaginary part to zero. Samples from 0 to N/2 of complex DFT correspond to the real DFT's spectrum.


Monday, June 20, 2016

ARM Cortex-M3 (STM32F103) Project - 32 Point DFT Audio Spectrum Analyzer

In this project, I made an audio spectrum analyzer project using ARM Cortex-M3 (STM32F013C8) and LCD 16x2. This project is the application of the real DFT algorithm from my previous post. I used 32 point real DFT for this project. 32 point DFT will transform 32 samples of time domain signal to 17 point frequency domain signal. The first point of frequency domain signal is DC. I will only display AC part (16 point) of frequency domain signal, which is from index 1 to 17 into 16 columns of LCD 16x2.


My audio sampling rate is 35.15kHz. So, the maximum frequency domain signals that can be displayed is up to 17.5kHz (Nyquist's theorem) and the resolution is 17.5kHz/161kHz.

The circuit for this project is same with the circuit for my simple audio effect project. The only differences is the LCD 16x2 and there is no dip switch circuit. You can see the detail about this circuit on this post. For the LCD, I used the custom character feature to create 8 type of bar graph. If you want to learn how to create custom char on LCD 16x2, you can see this tutorial.

Saturday, June 18, 2016

Real DFT Algorithm Implementation Using C++ Programming Language

Fourier analysis is a family of mathematical techniques for decomposing signals into sinusoids. Discrete Fourier Transform (DFT) is one of the Fourier transform family. There are four types of Fourier transform:
  • Fourier Transform: is used for signals that are continious and aperiodic.
  • Fourier Series: is used for signals that are continious and periodic.
  • Discrete Time Fourier Transform (DTFT): is used for signals that are discrete and aperiodic.
  • Discrete Fourier Transform (DFT): is used for signals that are discrete and periodic.

The only type of Fourier transform that can be used in DSP is the DFT. Because digital computers can only work with information that is discrete and finite in length. Real DFT is a version of the DFT that uses real numbers to represent the input and output signals. While the DFT is uses complex numbers to represent the input and output signals. In this post I will focus on how to implement real DFT algorithm using C++. This post is based on The Scientist and Engineer's Guide to Digital Signal Processing book. This book is very good for beginner to learn DSP.

Thursday, June 2, 2016

ARM Cortex-M3 (STM32F103) Project - DSP Audio Effect

In this project, I made a simple real-time DSP (Digital Signal Processing) project using ARM Cortex-M3 (STM32F013C8). The signal processed in this project is audio signal that come from electronic devices through 3.5mm audio jack. The audio signal is processed using STM32F103C8 microcontroller.


There are 3 simple audio effect that implemented in this project. These effects are low pass filter, pitch up, and pitch down. The audio output from this microcontroller is sent to an active speaker. This is block diagram of this system:


Tuesday, May 24, 2016

VHDL Tutorial - Xilinx ISE - Make A New Project for Digital Circuits Simulation

In this article, I will share about HDL (Hardware Description Language) and Xilinx ISE simulator. HDL is used for design digital circuits. There are 2 type of HDL that commonly used, VHDL and Verilog. VHDL syntax is like Pascal language, while Verilog is like C language. HDL has differences with traditional programming language such as Pascal and C. In traditional programming language, all statements always executed sequentially. In HDL, there are statements that can be executed concurrently. HDL can be used for designing a digital ASIC or programming an FPGA.


FPGA (Field Programmable Gate Array) is consists of many basic digital circuit blocks. This circuit block is usually called LUT. FPGA can be used for implement flexible digital circuits, because FPGA is like microcontroller that can be programmed using a hardware programmer. On a FPGA, we can create any digital circuits from basic combinational circuits such as adder, decoder, multiplexer up to a complex system like a microcontroller. We can create a full function microcontroller such as AVR ATmega inside a FPGA. FPGA is also used for simulation when prototyping a digital IC before go to the custom ASIC development process. There are 2 commonly used FPGA, Altera and Xilinx. These FPGA has an IDE, for Altera is Altera Quartus and for Xilinx is Xilinx ISE.


ASIC (Application Specific Integrated Circuit) is an IC that has a specific function (not flexible like FPGA). ASIC can be an analog, digital, mixed-signal, or RF IC. The process of creating an ASIC is quite complex. The process is begin from the design, synthesis, routing, fabrication, and testing. This complete and detail process can be learned from microelectronics lecture. For your information, there are several software used for design ASIC such as Synopsys, MentorGraphics, and Cadence. These software are called EDA (Electronic Design Automation) software.

Monday, April 25, 2016

ARM Cortex-M3 (STM32F103) Tutorial - SPI Master

In this tutorial, I will explain about SPI communication protocol and how to use it on STM32F103 microcontroller. SPI (Serial Peripheral Interface) is a synchronous serial communication protocol. With SPI, in addition to transmitting and receiving lines, there is a third line that used for clock line. Each slave devices also has a chip select (enable) pin. These pin is used for activate the slave devices. So, to use SPI, we need 2 wire for data lines (MOSI, MISO), 1 wire for clock line, and 1 wire per device for chip select line. MOSI (Master Out Slave In) is used for data transfer from master device to slave device. MISO (Master In Slave Out) is used for data transfer from slave device to master device.


SPI communication is different from other serial communication especially on data transfer. There are no concept like transmit and receive data, but there is a data trading concept. When data trading occurs, the data bits in master register is traded with the data bits in slave register on every clock from master (one data bit per clock tick).

Saturday, April 23, 2016

ARM Cortex-M3 (STM32F103) Tutorial - LCD 16x2 Library

In this tutorial, I will share about LCD 16x2 library. With this library, you can easily use LCD 16x2 with STM32F103 microcontroller. This library contain 2 file: lcd16x2.h and lcd16x2.c files. If you want to know the more detail how the LCD 16x2 works, you can see this tutorial.


Saturday, April 16, 2016

ARM Cortex-M3 (STM32F103) Tutorial - FreeRTOS - Task

In this tutorial, I will share how use an RTOS on STM32F103 microcontroller. I use FreeRTOS for this tutorial. RTOS is usually needs when an embedded system must responds to an event within a strictly defined time.


In this tutorial, I will make RTOS task with 3 LED that blinks at different frequency. First thing to do is to download FreeRTOS library. The next step is to make a new project in Keil uVision and setup the configuration for using FreeRTOS on STM32F103.

Thursday, March 17, 2016

ARM Cortex-M3 (STM32F103) Tutorial - I2C Master

In this tutorial, I will explain about I2C protocol and how to use it on STM32F103 microcontroller. I2C (Inter-Integrated Circuit) or sometimes called TWI (Two Wire Interface) is a synchronous serial protocol that only need 2 wire for communication. These wire are SCL for clock line and SDA for data line. Using I2C bus, you can connect devices like temperature sensor, EEPROM, RTC, etc (up to 112 device) just using two wire (plus GND wire). For accessing these device, I2C use 7-bit address. Theoretically 7-bit address space allows 128 addresses, however some addresses are reserved for special purpose. Thus, only 112 address can be used. There is also special method to use I2C with 10-bit address.


I2C is multi-master and multi-slave bus. I2C bus can consists of one or more master device, but only one master device can have an access to I2C bus each time. To communicate with a slave device, master is responsible for sending clock to the slave device. Clock signal is always generated by master. I2C drivers are open-drain, means that they can pull the signal low, but can't drive it high. On each signal line (SCL and SDA) must have a pull-up resistor to restore the signal high when no device is asserting it low.


Monday, February 29, 2016

ARM Cortex-M3 (STM32F103) Tutorial - 4x4 Matrix Keypad

Embedded system applications usually require large number of buttons connected (ex. calculator, cell phone). Keypad is one of the input device that commonly used in embedded system that require large number of buttons. 4x4 matrix keypad have 16 buttons. We can connect this buttons directly to GPIO pin, but it will eat up precious GPIO pin (If we have 16 buttons, then we need 16 GPIO pins). To avoid this trouble, keypad use technique that will save GPIO pin. In this technique, buttons are connected in a matrix (row/column) style.


The internal connection of the buttons in 4x4 matrix keypad is like this:


Sunday, January 31, 2016

ARM Cortex-M3 (STM32F103) Tutorial - Unipolar Stepper Motor

In this tutorial, I will share how control a unipolar stepper motor using STM32F103 microcontroller. If you don't know the basic of the stepper motor, I suggest you to read this article first. To control a stepper motor from microcontroller, we can't directly drive it with GPIO pins because GPIO pins have maximum current that can sink or source from it. To overcome this problem, we can use driver circuit. The driver circuit for unipolar stepper motor can be built by using 4 transistors to drive large current every 4 wires of a stepper motor. It also can be built with ULN2003 IC. This is the circuit for driving a unipolar stepper motor from microcontroller by using ULN2003 IC:


In this tutorial, I will use 28BYJ-48 stepper motor. This motor is very cheap and it also comes with driver module based on ULN2003 IC. This motor runs with 5V supply and has gear inside. The gear reduction ratio is approximately 64:1. If you search from internet, other people say that the gear reduction ratio is actually 63.68395:1.

 

Friday, January 29, 2016

Basic of Stepper Motors

A stepper motor is an electromechanical device which converts electrical pulses into discrete mechanical movements. The shaft of this motor is rotates in discrete step increment when electrical pulses are applied in a proper sequence. Every discrete step of a stepper motor is measured in degree (it can be 1.8° or even smaller depends on the stepper motor type and stepping technique).


This kind of movement is different from DC motors. DC motors is rotates continuously when there is a voltage applied to it and stops when the voltage removed. When the voltage applied to DC motors reversed, the rotation is also reversed. For the stepper motor, we can change the direction of the shaft rotation by reverse the sequence of the applied pulses. The speed of stepper motor shaft rotation is directly related to the frequency input of the pulses. The length of rotation of the stepper motor is directly related to the number of pulses applied.

Sunday, January 10, 2016

ARM Cortex-M3 (STM32F103) Tutorial - System Timer - Delay Function

In this tutorial, I will share how to use system timer (SysTick) for making delay functions. SysTick is a basic countdown timer. SysTick can be used by an operating system to ease porting from another platform. SysTick can be polled by software or can be configured to generate an interrupt. To use SysTick we can reload a value to the reload value register. SysTick reload value register supports value between 0 - 0x00FFFFFF (24-bit).

SysTick can be configured through the 4 registers:


Saturday, January 2, 2016

ARM Cortex-M3 (STM32F103) Tutorial - GPIO - Read Push Button/Switch

In this tutorial, I will explain how to use STM32F103 GPIO peripheral for read input from push button. GPIO (General Purpose Input Output) on STM32F103 can be configure to 4 different modes (input mode, output mode, analog input mode, alternate function mode). For read input from push button, we need to configure GPIO in digital input mode.


STM32F013 has 3 input mode (digital input): input with internal pull-up, input with internal pull-down, and input floating. The logic voltage of STM32 microcontroller is 3.3V, so the logic voltage for GPIO input pins is also 3.3V, but there are several pins that have 5V tolerant. So, we can input 5V logic level to this 5V tolerant input pins. This table below shows I/O voltage level on STM32F103 input pins.

Friday, January 1, 2016

ARM Cortex-M3 (STM32F103) Tutorial - GPIO - Control LED On/Off

In this tutorial, I will explain how to use STM32F103 GPIO peripheral for controlling a LED. GPIO (General Purpose Input Output) on STM32F103 can be configure to 4 different modes (input mode, output mode, analog input mode, alternate function mode). For controlling LED on/off from GPIO, we need to configure GPIO in output mode.


There are 2 output modes on STM32F103. Their modes are output open drain and output push-pull. The logic voltage of STM32F103 is 3.3V, so their port bit output voltage is 3.3V. This is the characteristic of I/O port bit when configured as output mode: