Arduino an Explanation – AVR @ Heart

I have been asked again and again by my friends and students to use Arduino or not and some people who are using AVR asked me if Arduino is better and some who were using Arduino asked the same about AVR. Well, here it goes, [this is all that I know, haven’t researched or confirm any of this while writing it – this became a bit longer than I had initially thought].

To understand what is Arduino, lets see how AVR works. To use AVR, usually the following is done in order.

  • Install ATMEL Studio on your PC if you dont have it.
  • Make a new project, select the AVR you like.
  • Write the CODE in the source file, standard C/C++ code works. If you want to use something special like LCDs or UART or something, proper Libraries make work easier otherwise that too can be one by using C code and referring to the datasheet.
  • Build/Compile/Make whatever, get the HEX file (look in the DEBUG folder).
  • Upload/Burn/Flash that Hex File to the AVR using a Programmer (a separate Hardware device – USBasp is the BEST).
  • Once the AVR is programmed with the HEX file, it needs to be on a circuit with power supply, reset circuitry, oscillator and any other component etc required by your project. Usually it is a Development Board, or an AVR on a breadboard or maybe a project PCB which has everything on it including a programming port (ICSP/ISP Connector).
  • It should WORK!

Hoping that you did everything above correctly from writing proper code to having the right controller IC to a working programmer and a working/tested circuit with your AVR IC in it and you should see your code working.

Usually mistakes happen in making that AVR circuit or the programmer doesn’t work or the connections from the programmer to the AVR are loose/broken, resulting in frustration and waste of time, usually new comers at this point think of leaving the AVR world and moving on.

This is where ARDUINO comes, Arduino is basically a prefabricated PCB aka circuit board with

  • an AVR Micro-controller (ATMega8/328/2560 etc) on it +
  • Power Supply circuitry +
  • Programmer Support (allows programming) +
  • Pins provided in easy to use connectors and numbered from 0 to 13 and A0 to A5 (talking about Uno here)
  • an easy to use Software ARDUINO IDE
  • easy to use code/language – basically it is just C/C++ functions, more about Arduino language here
  • One button/click program UPLOAD/test

So an Arduino looks very easy for any beginner to use, but KNOW that it has the same AVR micro-controller and the IDE supports C/C++ completely and you can still use any and all AVR registers directly, but that might break some of the Arduino functions.

So anyone using AVRs, I would suggest STICK with it and learn it properly unless you are stuck in a situation where you dont have the time to learn AVR now, then move to Arduino, do your task and then come back to AVR and learn it. [here I mean the ATMega series in general]

Those using Arduinos, it is OKAY to use it at any and all levels including and beyond B.E. anyone who says this is kid stuff does not know that it is the same AVR as any other – it is upto the programmer to write powerful code for it.

As For myself, I use Arduinos to prototype faster, this includes using Arduino hardware and shields and the Arduino IDE/code – however after basic prototyping I move my projects to custom made AVR boards, sometimes with the same arduino code and sometimes I optimize the code properly and either rewrite it completely in Atmel Studio using the standard C/C++ and my own custom libraries or mix my code with the Arduino code.

Simulating Arduino [Steps for Windows/PC]

This is a STEP-by-STEP post, no-nonsense approach to simulating an Arduino on your PC, for those who don’t have the actual Arduino hardware, but have the following Required Software:

From here on, I will be simply providing the steps of the process, no talk about what and how, just the steps, follow them and you will hopefully be able to see simulation of arduino code within your PC.

  1. Open Arduino Software
    — Select Arduino Uno from Tools(menu)>>Boards
    — Select Preferences from File Menu
    — Check the compilation box after the Show verbose output during:
  2. Write your program in Arduino, anything, or simply open some example program.
  3. Once done with the code, CLICK ON VERIFY,
    the RIGHT/check button on top-left – do not click on Upload, cause you don’t have the Arduino connected.

    verify-not-upload
    verify-not-upload
  4. As the arduino IDE verifies and compiles your code, you will see the output of the compilation process as it happens,
    once done, it will show something like this at the bottom LOG window (black area).
    C:\Users\ZAIDPI~1\AppData\Local\Temp\build3564184540682511069.tmp\Blink.cpp.hex
    Binary sketch size: 1,084 bytes (of a 32,256 byte maximum)

    hex-file-address
    hex-file-address
  5. I have only shown the last few lines,
    Copy the PATH of the hex file, complete path from the drive root to .hex
    C:\Users\ZAIDPI~1\AppData\Local\Temp\build3564184540682511069.tmp\Blink.cpp.hexThe arduino Part is DONE, now we move to Proteus.
  6. Open Proteus (ISIS) and add an ATMega328P into the Editing Window of Proteus.
    [press P for Part, search for ATMega328P and then add it, first to library then to the editing area, place part]
  7. Add Power to the AVCC and AREF by attaching them to 5V/VCC/Power Rail
  8. Now double click on ATMega328P to open the properties page, do the followign changes:
    — Set the CLKDIV8 option to (1) Unprogrammed
    — Set the CKSEL Fuses option to (1111) Ext. Crystal 8.0-MHz
    — in Advanced Properties section, write in 16000000 as the value of Clock Frequency Property
    — PASTE the address of HEX file, previously copied from Arduino software in the Program File option.
    Press OK, to close the properties window

    avr-properties-in-proteus
    avr-properties-in-proteus
  9. ADD any circuit, components etc in Proteus as you would with the actual ARDUINO

    simple-circuit-for-blinky
    simple-circuit-for-blinky
  10. PRESS PLAY
  11. Now, whenever you change code in arduino, just click on VERIFY to re-compile it, the hex file will remain the same and you can simply test the new code by stopping and re-starting the proteus simulation.

Project Files: Tachtastic – AVR Tachometer

Tachtastic – an Image from the old days

On demand of a site-visitor (Mohsen) I have uploaded all the relevant files that I had for the project Tachtastic: AVR Tachometer, you can download and view them. The files are more than a year old and show how I coded back then and were not meant for uploading – but now that I have seen it myself, seems to be well-documented not well coded though.

Download the below provided rar file, it contains all of the files that I have, including 2 versions of AVR Code, schematic files made in Circuit Wizard, PCB files [pdf] and images of the circuit.

There have already been 2 posts about this Tachtastic project and this being the third one will probably be the last one unless I make another AVR Tachometer, Tachtastic v2.0.

  1. Tachtastic Project Details
  2. Tachtastic Image Gallery

Without any further delay, here is the download link:

[Download not found]

Now that you have downloaded the rar file, this is what you will find inside, 4 folders:

tachtastic-folder-details

  • Circuit-files
    • This folder contains Circuit Wizard files of the circuit, which has both the schematic and the PCB layout, plus schematic and PCB layout in PDF files if you don’t have circuit wizard, multiple views of the circuit as circuit wizard had a number of views to choose from.
  • MISC
    • The MISC folder, contains things like datasheets, mechanical drawing of LCD that I used and a couple other things used and downloaded during the course of making the project.
  • Tachtastic
    • This is the main folder which contains the AVR Studio v4 solution, all source files and related files etc included. I tested it that it was compiling before uploading, so it should compile without any problem. I myself have gone through the code, it seems I had commented it when I was making the first time, so looks good enough and I am leaving the understanding of the code to you.
  • tachometer-01
    • Another AVR Studio v4 project, haven’t even seen the code, but seems relevant as it was in the same folder, maybe it is some older version of the code I was writing.

Phase and Integral Cycle AC Power Control with Arduino

Phase and Integral Cycle AC Power Control with Arduino
Phase and Integral Cycle AC Power Control with Arduino

What you see above is a project made for my Power Electronics Course, last term, finally completed and submitted. It is an AVR based board having 2 optically-isolated TRIACs for AC Power Control and implements both Phase Control and Burst Fire Control on each of the TRIACs. Controllable by an NEC IR Remote, shows status on Text LCD and the complete code was written in Arduino IDE [though there is some non-arduino/AVR code too].

The circuit above can be distributed into 3 parts, Power Supply, Controller and TRIACs.

Power Supply

The Power Supply for this board comes in the form of 220V AC from the wall outlet into the green terminal at the top-centre, which gets stepped-down by the transformer to 20V AC. The 20V AC is half-rectified by the 1N4007 diode [above the blue terminal] and is fed into the 15v regulator 7815 which feeds the next regulator 7805 to get a stable 5V DC supply for the controller circuitry.

The small white IC that you see is H11AA1 which detects the zero-crossings in the AC Line, I fed it stepped down AC supply [after the transformer]. It gives a pulse at every zero crossing and the whole AC Control relies on the signals coming from this IC. the Zero detect pulse goes to the INT0 pin of AVR, D2 pin on Arduino.

And what project would be complete without a Red LED to indicate Power.

Power Supply Portion - AC Supply to 5V DC with Zero Crossing Detection
Power Supply Portion: AC Supply to 5V DC with Zero Crossing Detection

 

Controller – AtMega8 / Arduino

I used an AtMega8 as the controller in this project running at 16MHz (hidden beneath the LCD) and programmed it via the Arduino IDE, using a USBasp programmer, the connector to the right is the ISP connector.

I used the Arduino environment as I wanted to use the IR Remote Library from AdaFruit and the LCD Library along with wanting to keep it simple and clean. The pinout of the LCD and the IR sensor (Black Component at the bottom) etc is provided in the arduino code, so I will not dwell in the schematic details here. It is to note that the IR remote I had was not working properly with the library so I had to do a few hacks in the original library. [code details in a later post]

Controller Portion - AtMega8 + LCD + IR = Arduino at 16MHz
Controller Portion: AtMega8 + LCD + IR = Arduino at 16MHz
[Download not found]

 

AC Power Control – TRIACs

This is the portion of the circuit which controls AC Power, the TRIACs used are BTA41 which are coupled to the controller by optical isolators MOC3011 (the white ICs). I am a bit paranoid when working with high voltage so I put up a plastic sheet over the 2 TRIACs and the bottom side is hidden with a card-sheet so no joints are exposed from below as well. Both TRIACs share teh same heat sink, an aluminum piece I found lying around, drilled it to use with the TRIACs. As labelled, one TRIAC controls the power by INtegral Cycle control method and the other uses Phase Control.

AC power Control Portion: TRIAC circuit + optical isolator + with plastic sheet and heatsink
AC power Control Portion: TRIAC circuit + optical isolator + with plastic sheet and heatsink

Code and other details on how the circuit is working will come in another post.

Vero-BoArduino

Vero-bo-Arduino

Recently I have been using Arduino more and more, and since I don’t own any actual Arduino boards I had to put the hex generated by the Arduino IDE to my custom AVR Boards either manually or by using the “Upload Using Programmer” option in the IDE.

With a USBasp programmer, you can program an AVR from the Arduino IDE by pressing Ctrl+Shift+U, just need to edit the boards file and add a new board profile with parameters same as your custom board.

I stumbled across a GitHub project which employs VUSB and USBasp and AVRDude supporting bootloader and allows to turn regular ATMega8 Boards into Arduino Boards with direct USB Connection and can be programmed directly via the IDE like regular Arduino Boards, the only catch being that there is no Serial Interface via the USB Port and the boards needs to be reset every time the board needs to be flashed.

GitHub Repo Link:    https://github.com/baerwolf/USBaspLoader

Many Thanks to Stephan Baerwolf for his Git-Repo and for all his help.

Instead of making a PCB, I took the path same as the tinyUSBboard and made a vero-board circuit. I made it somewhat shield-compatible by putting in the headers in places similar to the Arduino Boards. tinyUSBboard – the diy AVR (VUSB) board http://matrixstorm.com/avr/tinyusbboard/

vero-bo-arduino