Single Phase Inverter based on Arduino Uno or MEGA2560 - Page 1
Forum section: electronics / projects

author: hussamaldean
author_rank: Unknown
timestamp: January 22, 2018, 09:36:04 am
content: Hi all,I build a single phase inverter based on SPWM technique. the code took me like one month to build since the traditional API of Arduino don't offer great performance compared with direct register manipulation.Theory:###Basic PWMPulse width modulation’s (PWM) main use is to control the voltage supplied to electric circuits, it does this by rapidly switching a load on and off. Another way of thinking of it is to consider it as a method for a digital system to output an analogue signal. The figure below shows an example of a PWM signal.Figure 1-1There are two properties to a PWM signal, the frequency which is determined by the period of the signal and the duty cycle which is determined by the high-time of the signal. The signal in figure above has a period of 250?S which means it switches at 4KHz. The duty-cycle is the percent high time in each period, in the last figure the duty-cycle is 60% because of the high-time and period of 150?S and 250?S respectively. It is the duty-cycle that determines average output voltage. In figure above the duty-cycle of 60% with 5V switching voltage results in 3V average output as shown by the red line. After filtering the output a stable analogue output can be achieved. the figure below shows PWM signals with 80% and 10% duty-cycles. By dynamically changing the duty-cycle, signals other than a flat output voltage can be achieved.Typical microcontroller PWM implementationThis section describes how micro-controllers use timers/counters to implement a PWM signal, this description relies heavily on the figure below. Here the blue line represents a counter that resets after 16000, this gives the period of the PWM and also the switching frequency (fs), if this micro has a clock source of 16MHz, then fs will be 16×10^6/16×10^3 = 1KHz.The two other values of 11200 and 800 shown as the gree and red line, they represent compare output values of the micro. When the counter reaches this values the micro can change the output of some pins. In this case two pins are set to HIGH when the counter resets and then Set low when the counter reaches each of the output compare values. This determines the high time and therefore duty-cycle of the PWM. It's important to understand how a PWM is typcialy set up in a micro, as the explanation of the code in the next section will not make sense otherwise.Sinusoidal PWMA sinusoidal PWM (sPWM) signal can be constructed by dynamically changing the duty- cycle. The result is short pulses at the zero-crossings and long pulses at the wave peaks. This can be seen in the figure below.The figure shows negative pulses which is not possible on most micro-controllers. Instead normally this is implemented with two pins, one pulsing the positive half of the sin wave and the second pulsing the negative half, this is how it is implemented in this repo as having the signal split across two pins makes sense if the signal is going to be used to control a H-bridge.Code and ExplanationIn this chapter we'll step through the code found in the folder sPWM_basic, and then the difference between it and the code found in the folder sPWM_generate_lookup_table will be discussed. Code found in sPWM_atmel is for use on an atmel chip without using the arduino IDE.The code toggles a pin for every period of the sine output in order to make it osilliscope friendy.sPWM_BasicThe following C code implements an sPWM on a Atmel micro-controller. The signal is generated on two pins, one responsible for the positive half of the sine wave and the other pin the negative half. The sPWM is generated by running an (ISR) every period of the PWM in order to dynamically change the duty-cycle. This is done by changing the values in the registers OCR1A and OCR1B from values in a look up table. There are two look up tables for each of the two pins, lookUpTable1 and lookUpTable2 and both have 200 values. The first half of lookUpTable1 has sin values from 0 to ? and the second half is all zeroes. The first half of lookUpTable2 is all zeroes and the second half has sin values from 0 to ? as shown in figure below.however, this method requires a lot of memory since you need two tables to update the PWM but in my code only one lookup tableyou can find the code from this linkhttps://github.com/hussamaldean/sPWM-ATMELBTW, this is my first project based on direct registry programmingHere is some pictureyou will find the circuit diagram in the attachment as PDF fileRegardsThis topic is open for discuss, modification and enhancement for the code, circuit and hardware

author: siconic
author_rank: Contributor
timestamp: January 26, 2018, 04:45:54 am
content: I know its off topic, but I have been looking into buying a PC based Hantek USB O-Scope. I see you have one, and I would like to know how you like it, and if it fits most of the uses you have put it to task on?Sent from my SM-G950U using Tapatalk

author: cowasaki
author_rank: Frequent Contributor
timestamp: January 27, 2018, 10:36:21 am
content: What are your plans with it? Are you going to package up the code and turn it into functions that other people can use? I did this with the DUE graphical user interface which then other people started to add to and improve later.

author: hussamaldean
author_rank: Unknown
timestamp: January 29, 2018, 11:55:27 am
content: Quote from: siconic on January 26, 2018, 04:45:54 amwell, if you are not using to measure hight voltage such as main voltage or high frequency beyond 10MHz it will fit your need without any problemQuote from: cowasaki on January 27, 2018, 10:36:21 amjust having funand if it possible to send me the code and schematics ?

author: cowasaki
author_rank: Frequent Contributor
timestamp: January 29, 2018, 12:03:43 pm
content: Quote from: hussamaldean on January 29, 2018, 11:55:27 amIt's on the Arduino.cc forum if you go to the DUE specific section and search for DUEGUI. It uses the 7inch touch screen shield but I was looking at designing my own shield that handles the screen better and maybe has a power, mouse, RTC and keyboard input. All these would be very simple and would make the DUE very simple to connect up to a screen and then leave plenty of pins free (which I was basically going to add 3.5/5v converters on to several of them). It's on the long list of things to do!

author: hussamaldean
author_rank: Unknown
timestamp: January 29, 2018, 05:18:58 pm
content: Quote from: cowasaki on January 29, 2018, 12:03:43 pmwill it work with RA8875 from adafruit ?

author: cowasaki
author_rank: Frequent Contributor
timestamp: January 29, 2018, 05:41:32 pm
content: Quote from: hussamaldean on January 29, 2018, 05:18:58 pmNo idea. I can give you a link to a board and screen that will work. I might have an unopened spare board if you need one but I would have to check tomorrow.

author: hussamaldean
author_rank: Unknown
timestamp: January 29, 2018, 05:59:13 pm
content: Quote from: cowasaki on January 29, 2018, 05:41:32 pmok send them please