[Ralph] has been working on an extraordinarily tiny bootloader for the ATtiny85, and although coding in assembly does have some merits in this regard, writing in C and using AVR Libc is so much more convenient. Through his trials of slimming down pieces of code to the bare minimum, he’s found a few ways to easily trim a few bytes off code compiled with AVR-GCC.
To test his ideas out, [Ralph] first coded up a short program that reads the ATtiny85’s internal temperature sensor. Dissassembling the code, he found the a jump to a function called __ctors_end: before the jump to main. According to the ATtiny85 datasheet, this call sets the IO registers to their initial values. These initial values are 0, so that’s 16 bytes that can be saved. This function also sets the stack pointer to its initial value, so another 16 bytes can be optimized out.
If you’re not using interrupts on an ATtiny, you can get rid of 30 bytes of code by getting rid of the interrupt vector table. In the end, [Ralph] was able to take a 274 byte program and trim it down to 190 bytes. Compared to the 8k of Flash on the ‘tiny85, it’s a small amount saved, but if you’re banging your head against the limitations of this micro’s storage, this might be a good place to start.
Now if you want to hear some stories about optimizing code you’ve got to check out the Once Upon Atari documentary. They spent months hand optimizing code to make it fit on the cartridges.
[Davide] saw our recent post on magnetic levitation and quickly sent in his own project, which has a great explanation of how it works — he’s also included the code to try yourself!
His setup uses an Atmega8 micro-controller which controls a small 12V 50N coil using pulse-width-modulation (PWM). A hall effect sensor (Allegro A1302) mounted inside the coil detects the distance to the magnet and that data is used by a PID controller to automatically adjust the PWM of the coil to keep the magnet in place. The Atmega8 runs at 8Mhz and the hall effect sensor is polled every 1ms to provide an updated value for the PWM. He’s also thrown in an RGB LED that lights up when an object is being levitated!
So why is there a kid with a floating balloon? [Davide] actually built the setup for his friend [Paolo] to display at an art fair called InverART 2013!
After the break check out the circuit diagram and a short demonstration video of the device in action!
Oh yeah, those of you not impressed by magnetic levitation will probably appreciate acoustic levitation.
Continue reading “AVR Atmega based PID Magnetic Levitator”
If you’re using an AVR microcontroller and you’d like to add USB to a project, there are a lot of options out there for you. Both LUFA and V-USB add some USB functionality to just about every AVR micro, but if you’d like a native serial port, your only options are to look towards the USB-compatible Atmel micros.
[Ray] looked at the options for adding a USB serial port and didn’t like what he saw; seemingly, this was an impossible task without a second, more capable microcontroller. Then he had an idea: if the goal is only to transfer data back and forth between a computer and a microcontroller, why not write an HID-class USB serial port?
[Ray] based his project on The V-USB library and created a new HID descriptor to transfer data between a micro and a computer. While it won’t work with a proper terminal such as Putty, [Ray] managed to whip up a serial monitor program in Processing that’s compatible with Windows, Linux and OS X.
In the video below, you can see [Ray] using an ATmega328p with a standard V-USB setup. He’s transferring analog values from a photoresistor as a proof of concept, but just about everything that would work with a normal serial port will work with [Ray]’s library.
Continue reading “Serial USB for Any AVR Microcontroller”
It’s not that breadboarding AVR circuits is difficult. But you have to admit that it takes some time to set everything up. We don’t label the top of our DIP chips so that you know what each pin does just by looking. Which means that wiring up the programmer involves pulling out the datasheet. [Vinnie] found the solution to this problem which is to make one of these interface PCBs for each AVR chip family. The long pins make it easy to drop over the top of your microcontroller, which is where the name comes from.
His first stab at the idea was just a hunk of home etched PCB which broke out the programming pins into the 6-pin ICSP standard. This second rendition uses the 10-pin standard and adds a few extras into the mix. He included decoupling capacitors which need to be used in every circuit anyway. There’s a crystal along with its load capacitors. This clock source is a snap to enable by burning some fuses. If you choose to use the internal oscillator instead this hardware won’t interfere. The LED is used to get you up and running with blinky firmware as quickly as possible. He plans to add jumper in the next revision which can disconnect this components from the I/O pin. Now you just need to add a 10-pin header to that USB keyboard AVR programmer and you’re in business.
This project is reminiscent of the old days when window managers were an amazing new idea. The difference is that this window-based GUI is running on an ATmega1284 microcontroller. But the behavior and speed of the interface is pretty much exactly what you’d expect if working on an early 90’s home computer. It even uses a mouse as input.
So how is this even possible? The key to the project is a serial to VGA module which handles the heavy lifting involved with generating a VGA signal. We featured one of [Andrew’s] past projects which used an AVR chip to generate the VGA signal. But that doesn’t leave nearly enough cycles to implement something like a window manager, not to mention the fact that it got nowhere near the resolution shown here.
He uses a serial mouse with an RS-232 converter chip to interact with the windows. This is best shown in his video after the break. He’s able to generate and interact with new windows. He even implemented a set of rudimentary controls which allow him to adjust the theme of the windows and drive the audio playback feature included on that VGA controller he’s using.
Continue reading “GUI window manager on an AVR chip”
This simple circuitry makes up the hardware for [Andrew’s] AVR-based VGA generator. He managed to get an ATmega1284 to output a stable VGA signal. Anyone who’s looked into the VGA standard will know that this is quite an accomplishment. That’s because VGA is all about timing, and that presented him with a problem almost immediately.
The chip is meant to run at a top speed of 20 MHz. [Andrew] did manage to get code written that implemented the horizontal and vertical sync at this speed. But there weren’t enough clock cycles left to deal with frame buffering. His solution was to overclock the chip to 25 MHz. We assume he chose that because he had a crystal on hand, because we think it would have been easier to use a 25.174 MHz crystal which is one of the speeds listed in the specification.
Red, green, and blue each get their own two-bit range selected via a set of resistors for a total of 64 colors. As you can see in the video after the break, the 128×96 pixel video is up and running. [Andrew] plans to enlarge the scope of the project from here to make it more versatile than just showing standard images. The code (written in assembly) is available at his GitHub repository.
Continue reading “AVR VGA generator”
We’ve seen composite video out from AVR chips many times before. But we can’t remember coming across one that managed to produce a color signal. This project does just that, producing a color video signal from an ATmega168 without using external integrated circuits.
[CNLohr] is seen here showing off his accomplishment. You’ll remember him from the glass-slide PCB server project he’s been working on recently. This time around it’s a small piece of gaming hardware which he’s working on. But using four pins from the microcontroller, connected via resistors in parallel, he is able to generate a color NTSC signal without using a chip like the AD723.
After the break you can see the two minute demo in which he shows the game running for just an moment, then gives a general overview of how the signals are being built. There isn’t a ton of explanation, but he did post his code as well as a resource for you to teach yourself more about the NTSC standard. Maybe you can make a color version of that AVR tetris game?
Continue reading “Color NTSC video directly from an AVR chip”