www.postcogito.org
          ...sine propero notiones

Kiko
You are here: Kiko > PostsInEnglish > EnBlogEntry2008Feb10A Printable | topic end


Start of topic | Skip to actions
Versão em Português

Assembly phase I
The device still very much incomplete but already
capable of booting, communicating over serial and
measuring the line parameters. Click to enlarge.
Flattened top sine wave
Measuring the voltage at the MCU's ICP pin,
I was surprised to see that the sine wave top was
rather flattened out.

Starting Assembly of the Power Glitch Monitor

Rec 10-feb-2008 20:11

During the last couple weeks, my "copious" spare time was spent building the power glitch monitor prototype. I assembled the power supply, signal conditioning unit, the microcontroller and the serial level converter.

At this time the firmware supports:

  • Interrupt driven serial communcations with a 120-byte transmit FIFO;
    • simplifies programming because we can print considerably large messages and the interrupt routines take care of transmitting each byte;
  • A command line prompt with ultra simple line editor (ENTER/backspace only, no arrow keys) so we can input commands to the device;
  • The real time clock with calendar, properly incrementing months according to how many days each month has and correctly handling leap years up to 2099;
  • Routines to print numbers in fixed-point decimal;
  • Line frequency and voltage measurements;
  • Records last failure time and duration.

Currently supported commands are:

  • ver: shows version information
  • time: set current time
  • date: set current date
  • log: enable logging measurements once a second; any key disables the log
  • reboot: jumps to the bootloader for firmware upgrade

I took the picture moments before I soldered the crystal and the ISP connector. Just after I plugged it in, the frequency measurements got very near 60.00Hz just as I had predicted.

Even more surprising was to see that the voltage measurements also got within +/- 5V of the nominal 220V when using the exact multiplication constant of 2978 I had calculated in the Excel spreeadsheet. That was surprising, given so many things that could go wrong. I shook my head in amazement: I'm not really used to things working perfectly on the first try.

I changed the ADC firing routine (actually, the Output Compare 1A ISR) to pull the ICP pin to ground for a few microseconds just before the ADC starts measuring and plugged all that to the oscilloscope, so I could see exactly where the measurement was taking place. It was a bit past the peak of the wave; I reduced the tick count accordingly to put it as close to the center of the wave as I visually could. It did little difference to the measurement, though, because of a small surprise: the sine waveform from my power outlet isn't that pretty -- it has a strange flattened top, as shown in the figure.

Back to the software arena: with the serial communication working just fine, I thought of putting a bootloader so I don't even have to use my ISP programmer. I have a working and rather full-featured AVR910 compatible bootloader, but at 1KiB, it's kinda big and I'm starting to suspect that when completed, the firmware will barely fit the 8KiB program memory the ATmega8 has -- I'm just started and the firmware is already 3KiB in size.

Googling around I found this ~430 byte bootloader for the ATmega16 that uses the XMODEM protocol commonly available in terminal emulation programs to upload the firmware. I adapted it to work on the ATmega8 and optimized it for size, making it fit in mere 256 bytes -- the smallest bootloader size the ATmega8 supports. Now, it is quite minimalistic: it supports only writing to the flash; you can't read the flash, nor can you read/write the AVR built-in EEPROM nor the fuses. But it works like a charm with minimal program memory footprint -- get it here.

So far it's been a pretty easy ride. Now it's time to add the LCD, the serial EEPROM and code support for them. That will be fun.


Follow-ups:


top


You are here: Kiko > PostsInEnglish > EnBlogEntry2008Feb10A

top

Creative Commons License   The content of this site is made available under the terms of a Creative Commons License, except where otherwise noted.
  O conteúdo deste site está disponibilizado nos termos de uma Licença Creative Commons, exceto onde dito em contrário.