Saturday, March 9, 2013

From VB6 to .Net ( VB2010 )



After coding in VB6 for over 15 years, finally decided to move to VB2010.  As before, the project was already on hand and it was my last minute decision to move to .Net. I could have downloaded a trial version of VB2010 few years before and played with it, but with many different projects running simultaneously time was always short and that never happened.

I am not a pure software person, all my projects are more of hardware than software part. Software is only limited to GUI, Database, proprietary bus interface and data exchange with factory automation system.


Sponsor: www.avmicrotech.com/shop  eshop for your electronic needs


My first impression was total betrayal as I seemed to be programming in Visual C++  than VB. Common ActiveX like winsock was not available by default in Vb2010. Message read from serial port could not be written directly to Textbox.... different threads. As TCP/IP was to be used for data exchange with Host, I had to re-write the communication backbone which was not an ordinary ASCII stream but a complex system that was optimised for engineering data exchange. I had to transfer variables stored as Integer, single and double to byte stream of unsigned integer, 4byte floating point and 8 byte floating point.

But after 3 weeks of coding I was more than happy. It was very easy to come up with multi-threaded system where the data exchange with host was running independently from my user interface and background data collection part. Further all my data conversion were handled by native functions  Overall a much simpler and compact than my previous projects.

....cont

Friday, March 8, 2013

Arduino UNO Bootloader and Firmware



Arduino UNO by design has come out be a complex system, needing three different flash programs to make it run. I will show where these three are located and method to update them. Below excerpt is from Atmega8u2 /Atmega16u2 datasheet.


When the HWBE fuse is enable the PD7/HWB pin is configured as input during reset and sampled during reset rising edge. When PD7/HWB pin is ‘0’ during reset rising edge, the reset vector will be set as the Boot Loader Reset address and the Boot Loader will be executed .



Hence starting with Atmega8u2 / Atmega16u2 that is used as USB to UART, when it is first connected to the USB port of your PC, it is read as power on by the Atmega8u2 / Atmega16u2 and bootloader is skipped and it enters application section (i.e usb to uart) even though your HWB pin is pulled low (for UNO Rev3). However if you reset Atmega8u2 / Atmega16u2 it is read as reset by the uC and during the rising edge of reset signal the uC enters into the bootloader mode.


Sponsor: www.avmicrotech.com/shop   eshop for your electronic needs



So below are the configuration to flash different parts of devices on UNO

Device Section SourceMethod
Atmega8u2 / 16u2 Bootloader usbdfu Through ISP Header at top right
Atmega8u2 / 16u2 Application Section usbserial Reset Atmega8U2 by shorting reset to gnd to enter bootloader.
Atmega328 Bootloader Optiboot Through ISP Header at the bottom

Actually, the usbdfu and usbserial  are combined together in Arduino distribution as 1 hex file and can be downloaded in one go though Atmega8u2 /  Atmega16u2 6 pin ISP port and using AVR ISP.

.....cont


Wednesday, March 6, 2013

Arduino : Difference between UNO and Duemilanove bootloader


Some of the difference are very well known like smaller bootloader size, faster flash programming by UNO, replacement of FT232RL with Atmega8u2, however I would like to explore more on the technical and implication part.
1) EEPROM write- This will be missed as I would in many cases write configuration data in eeprom like calibration file etc. Though eeprom can always be updated through user code.


Sponsor: www.avmicrotech.com/shop eshop for your electronic needs



2) Adaboot no wait mode: This might have been added later in duemilanove, but it needs special mention.This is a check in bootloader to know the source of reset and react accordingly.Hence if uC enters bootloader due to watchdog reset or brown out reset it immediately leaves bootloader and jumps to main program.Hence other than hardware reset your uC will never enter bootloader.
3) Watchdog handling: The UNO bootloader has code to handle the watchdog timer if it is activated by setting WDTON in Fuse High Byte in your project. In older version the Arduino will stay in bootloader forever if WDT was enabled.

In addition to above some unnecessary zero initialisation commands are removed to save code space.

Hardware differences

1)On older boards, the FT232RL was also providing a free 3.3V output. In the UNO, a separate LP2985 LDO regulator produces 3.3V at 150mA DC from internal 5Volts.


2)The 16Mhz Crystal oscillator for Atmega328 is replaced with 16Mhz resonator (UNO Rev 3).

Board Reliability improvement upgrades

1)The UNO rev3 finally has diode to clamp reset pin voltage to 5Volts.

2)All UNO have varistor protection for USB D+ / D- signal lines. To prevent voltage spike destroying the Atmega16U2.



......cont


Arduino : My Learning Journey




I have been using Arduino from the time it first appeared in the market. Before  that I was using AVR studio / stk500 with Atmega8 and Atmega168. Atmega328 had not arrived yet. STK500 was a good prototyping platform where most of the AVR features like fuses could be set or reset. My first trial was to make and download the Arduino bootloader into an Atmega8, but due to some issue it kept failing which I soon  realised was due to the code compiling into a size bigger than the Atmega8 bootloader. I had no choice but to go debug the code and remove some redundant commands and finally was able to squeze in the code. I got two additional benefits from this study first I was able to reduce the bootloader delay to 1 sec and second I could enable the watchdog timer handling in the bootloader....


Sponsor: www.avmicrotech.com/shop eshop for your electronic needs


Watchdog

A micro-controller latch-up (hang) on a production machine is biggest nightmare for any hardware designer as this small insignificant event can cause unnecessary stoppage and activation of technicians. I was also bitten by the same fear when adding a uC (micro-controller) to carry out BCD to serial conversion in one of my projects. The uC latch-up would have resulted in bad reputation. I found a very unconventional solution. A watchdog was setup for a few seconds and nothing was done to handle it. so the system would automatically reset after a few seconds which was seamless to the operation. The system worked so flawlessly and thanks to Cygnal (now Silicon Labs) uC reliability, I have system running untouched for over ten year!!


Sponsor: www.avmicrotech.com/shop eshop for your electronic needs


Wiring or C

Recently I was requested by one of the faculty member of an Engineering college in New Delhi to setup some experiment for their embedded lab around Arduino Hardware. They were very surprised and happy when I configured  AVR studio to download compiled C programs directly to an Arduino board. With this the students could learn to program in real C or C++ using winavr and later use rich Arduino Libary to interface complex hardware like SD card or Ethernet controller.
I am of the opinion that Engineering students should retain and develop their C skills and at the same time learn  ARM processor. The cost of  ARM devices have dropped and boards are available at prices slightly higher than Arduino. I am seeing that engineering students at NUS Singapore directly start hardware programming on NXP arm boards in C and assembly (inline).

......cont