We love interrupts in our microcontroller projects. If you aren’t already convinced, go read the first installment in this series where we covered the best aspects of interrupts.
But everything is not sunshine and daffodils. Interrupts take place outside of the normal program flow, and indeed preempt it. The microcontroller will put down whatever code it’s running and go off to run your ISR every time the triggering event happens. That power is great when you need it, but recall with Spider-Man’s mantra: With great power comes great responsibility. It’s your responsibility to design for the implicit high priority of ISRs, and to make sure that your main code can still get its work done in between interrupt calls.
Put another way, adding interrupts in your microcontroller code introduces issues of scheduling and prioritization that you didn’t have to deal with before. Let’s have a look at that aspect now, and we’ll put off the truly gruesome side-effects of using interrupts until next time.
Continue reading “Embed With Elliot: Interrupts, the Bad”
Ready to feel inadequate with your programming skills? You’ve been warned. Take a look at [Voja’s] single chip video game console using the PIC24. It produces the VGA signal, 5-channel sound, and is presented in a gamepad form-factor with directional pad and two buttons.
He’s been working with PIC24 for a while now generating VGA signals, and he decided it might be fun to create a 2D video game… so he decided to see if he could program a replica of the old Spectrum game Jumping Jack (play it online here).
It uses a PIC24EP512GP202 microcontroller, complete with 512K flash memory, 48k data, and a whopping 28-pins. The game, which is extremely well documented, is laid out over on his projects page. It makes our heads spin just looking at it! This is a great project to compare with the ArduinoCade from last week. Both do an amazing job of pumping out audio and video while leaving enough room for the game to actually run.
Anyway, enough talking about it — just take a look at the following demo!
Continue reading “A Single-Chip Video Game Console”
What’s the biggest difference between writing code for your big computer and a microcontroller? OK, the memory and limited resources, sure. But we were thinking more about the need to directly interface with hardware. And for that purpose, one of the most useful, and naturally also dangerous, tools in your embedded toolchest is the interrupt.
Interrupts do exactly what it sounds like they do — they interrupt the normal flow of your program’s operation when something happens — and run another chunk of code (an interrupt service routine, or ISR) instead. When the ISR is done, the microcontroller picks up exactly where it left off in your main flow.
Say you’ve tied your microcontroller to an accelerometer, and that accelerometer has a “data ready” pin that is set high when it has a new sample ready to read. You can wire that pin to an input on the microcontroller that’s interrupt-capable, write an ISR to handle the accelerometer data, and configure the microcontroller’s interrupt system to run that code when the accelerometer has new data ready. And from then on everything accelerometer-related happens automagically! (In theory.)
This is the first part of a three-part series: Interrupts, the Good, the Bad, and the Ugly. In this column, we’ll focus on how interrupts work and how to get the most out of them: The Good. The second column will deal with the hazards of heavyweight interrupt routines, priority mismatches, and main loop starvation: the Bad side of interrupts. Finally, we’ll cover some of the downright tricky bugs that can crop up when using interrupts, mainly due to a failure of atomicity, that can result in logical failures and corrupted data; that’s certainly Ugly.
Continue reading “Embed with Elliot: Interrupts, The Good…”
What has six legs, 25 LEDs, a Microchip CPU, can be sewn into clothing, and even plugged into a Raspberry Pi? The answer, it turns out, is the CodeBug–a low cost computer board aimed at the educational market. These board were crowdfunded and are now available for general purchase. [Mike Redrobe] took one of the boards, connected a few servos and used the CodeBug’s Scratch-like language to create a small robot.
You can see the robot in the video below. Programs download via USB (the board looks like a USB drive). You can also send commands over USB to operate in tether mode, or you can directly plug the board into a Raspberry Pi.
Continue reading “There’s a Bug in My Robot”
Look at any sufficiently advanced CNC machine or robot, and you’ll notice something peculiar. On one hand, you have a computer running a true operating system for higher-level processing, be it vision or speech recognition, or just connecting to the Internet. On the other hand, you have another computer responsible only for semi-real-time tasks, like moving motors, servos, and reading sensors and switches. You won’t be doing the heavy-lifting tasks with a microcontroller, and the Raspberry Pi is proof enough that real-time functions aren’t meant for a chip running Linux. There are many builds that would be best served with two processors, but that may be changing soon.
Microchip recently announced an addition to the PIC32 family of microcontrollers that will support hardware virtualization. This addition comes thanks to the MIPS M5150 Warrior-M processor, the first microcontroller to support hardware visualization.
Continue reading “Hardware Virtualization in Microcontrollers”
Monitoring your home’s energy use is the best way to get a handle on your utility bills. After all, you can’t manage what you can’t measure! The only problem is that most home energy monitoring systems are cumbersome, complicated, or expensive. At least, until now. [Kevin] has created a new electricity meter based on Particle Photons which should alleviate all of these problems.
The Particle Photon (we get confused on the naming scheme but believe this the new version of what used to be called the Spark Core) is a WiFi-enabled development board. [Kevin] is using two, one to drive the display and one to monitor the electricity usage. This part is simple enough, each watt-hour is accompanied by a pulse of an LED on the meter which is picked up by a TLS257 light-to-voltage sensor. The display is a Nextion TFT HMI (touch screen) which is pretty well suited for this application. The data is corralled by emoncms, part of the OpenEnergyMonitor platform, which ties everything together.
For a project that has been done more than a few times, this one does a great job of keeping the price down while maintaining a great aesthetic. Make sure to check out the video below to see it in action.
Continue reading “Simplest Electricity Monitoring Solution Yet”
Before you overreact to the title, keep in mind the latest version of Eclipse is code named “Mars.” It is always a bit of a challenge to set up a generic ARM tool chain. If you don’t mind sticking to one vendor, shelling out a lot of money, or using Web-based tools, then you might not have this problem. But getting all the tools together can be annoying, at best.
[Erich Styger] works with students and knows they often stumble on just this step so he’s provided clear documentation for getting Eclipse, the ARM gcc compiler, and a full set of tools installed. He focuses on Windows and the Kinetis platform, but the steps are virtually the same regardless. Just get the right tools for your operating system and skip the Kinetis-specific parts if you don’t need them.
Continue reading “ARM Programming on Mars”