Wednesday, March 20, 2013

PCF8574 GPIO expander library for AVR Atmega - v01

The PCF8574 is a silicon CMOS circuit. It provides general purpose remote I/O expansion for most microcontroller families via the two-line bidirectional bus (I2C-bus).


PCF8574 lib is an AVR Atmega library for the PCF8574 i2c IO port expander. This library can run up to 8 PCF8574, it can read and write port status, and allows you to expand your Atmega ports.

Setup parameters can be found in file pcf8574.h

This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 1MHz.


Code


Notes
  • read risk disclaimer
  • excuse my bad english

Wednesday, March 13, 2013

AVR uartConfig - an atmega and arduino eeprom config library

Update to version 2014-06-13

AVR uartConfig is a small footprint library you can use to config your micro eeprom through uart communication.


AVR uartConfig is a set of tools running on Windows, Linux and Mac, made up or:
  • a avrgcc firmware library
  • a commandline utility
  • a gui tool


Applications
This library prevent you to wire up a disply and buttons to configure your micro eeprom. For example is it usefull to setup PID parameters of your robot by uart/bluetooth uart, or for other small devices that doesn't came with an output/input interface.


How does it works
Firmare side you have to setup an eeprom structure which contains all the variable you want to save on your eeprom and later you can read.
The same eeprom structure is replicated in the commandline utility config file.
So every times you want to write/read an element of your micro eeprom, you can run commandline utility which serialize your input value, prepare it to be written on eeprom, and then ask the firmware to write this parameter on eeprom.
To read a value, the commandline utility just ask firmware to return a specific eeprom byte interval, then it deserialize the value recived.
Serialization and Deserialization functions provide the way to "convert" the commandline input as a valid atmega eeprom variable input, and viceversa.
All the conversion are made client (commandline) side, firmware side we have a small footprint library.
To make this works we have setup the same struct on firmware and command line side.


Firmware Library
  1. include the library in your main file
  2. setup eestruct on firmware and commandline config file read EESTRUCT file for further info
  3. init your eestruct eerpm (optional)
  4. in the main loop get a character from uart, and use avruartconfig main check function to check if the character you get is a library command main function also need a pointer to the eestruct variable and eeprom variable

Firmware Library, Arduino Notes
Import avruartconfig library in your libraries folder.
Make sure your serial connection is not resetting your arduino every times the serial port is open, look here for info: http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection


Commandline Utility
Using the commandline tool you can setup you atmega. Commandline utility implements the setup procol client side. Setup eestruct configuration files, read EESTRUCT file for further info.
The command line utility makes use of libconfig, so to build it, you need to add libconfig library to your linker (-lconfig for the library, -L../lib/_select_os to select the library directory).
Check that you have execution permission on commandline binary.



GUI Utility
We also provide a Java gui tool which use the commandline utility. On first time execution you have to setup config parameters. The gui icon is part of the KDE Oxygen theme, released under GPL.
Sample configuration for avruartconfig_gui under:
Windows: bin path = avruartconfig_commandline-win.exe, port = 33, baudrate = 2400
Linux: bin path = ./avruartconfig_commandline-linux, port = /dev/ttyUSB0, baudrate = 2400
Mac: bin path = ./avruartconfig_commandline-mac, port = /dev/tty.SLAN_USBtoUART, baudrate = 2400



Devel Notes
This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 1MHz.
To build binaries, just use the workspace as provided, and select the proper "Release" for your o.s., if not listed, just add one. For the java gui, an ant build script (build.xml) is provided.


Changelog
  • 2014-06-13 A minor fix to the gui is added to prevent noisy connection communication error.
  • 2013-01-16 This version has many differences from the previous one, the most important is that the serialization and deserialization functions are implemented in the command line utility, in this way the firmware has a small footprint and use less memory.
    Also an arduino library is provided.
  • 2012-06-21 First release.


Code

Notes
  • read risk disclaimer
  • excuse my bad english

Wednesday, March 6, 2013

Controlling DC Motor speed and direction with AVR Atmega

updated library here: http://davidegironi.blogspot.it/2015/02/driving-dc-motor-using-pwm-with-avr.html

A DC motor is a mechanically commutated electric motor powered from direct current (DC). The stator is stationary in space by definition and therefore so is its current. The current in the rotor is switched by the commutator to also be stationary in space. This is how the relative angle between the stator and rotor magnetic flux is maintained near 90 degrees, which generates the maximum torque.



Here you can find three libraries to control DC Motor using Atmega micro.

The first one (lib_dcmotor) allow you to synchronously control motor in direction.

The second one (lib_dcmotorpwm) implements a way to control motor direction and speed asynchronously, using timers, by hardware PWM capabilities of Atmega micro. The average value of voltage (and current) fed to the load is controlled by turning the switch between supply and load on and off at a fast pace. The longer the switch is on compared to the off periods, the higher the power supplied to the load is, and the more the motor spin.

The third one (lib_dcmotorpwmsoft) does exactly the things of the library above, but implements a software PWM, leaving free the hardware PWM resource for other device, or for micro that does not have PWM hardware embedded.

All libraries can control up to 2 motors, more motors can be controlled with the third one libraries using output port expander.




All libraries was developed on Eclipse, built with avr-gcc on Atmega8 @ 1MHz.


Code


Notes
  • read risk disclaimer
  • excuse my bad english