Introduction to Microcontrollers - Timers
Timers - Because "When" MattersComputer programs are odd things, for one reason because they have no concept of time. They may have the concept of sequential execution, but the time between instructions can be essentially any number and the program won't notice or care (unless assumptions about time have been built into the program by the programmer). But the real world is not like this. In the real world, especially the real embedded world,...
Introduction to Microcontrollers - More On Interrupts
A Little More Detail About The Interrupt MechanismIt's time to look a little closer at what happens in an interrupt request and response. Again this is in general terms, and different microcontroller designs may do things somewhat differently, but the basics remain the same. Most but not all interrupt requests are latched, which means the interrupt event sets a flag that stays set even if the interrupt event then goes away. It is this latched flag...
Introduction to Microcontrollers - Interrupts
It's Too Soon To Talk About Interrupts!That, at least, could be one reaction to this chapter. But over the years I've become convinced that new microcontroller programmers should understand interrupts before being introduced to any complex peripherals such as timers, UARTs, ADCs, and all the other powerful function blocks found on a modern microcontroller. Since these peripherals are commonly used with interrupts, any introduction to them that does not...
Introduction to Microcontrollers - More On GPIO
Now that we have our LED Blinky program nailed down, it's time to look more closely at outputs, add button/switch inputs, and work with reading inputs and driving outputs based on those inputs.
It's ON - No, It's OFF - No, It's ON...I have to confess, I cheated. Well, let's say I glossed over something very important. In our LED Blinky program, we never cared about whether an output '1' or an output '0' turned on the LED. Since we were just...
Introduction to Microcontrollers - Hello World
Embedded Hello WorldA standard first program on an embedded platform is the blinking LED. Getting an LED to blink demonstrates that you have your toolchain set up correctly, that you are able to download your program code into the μC, and that the μC and associated circuitry (e.g. the power supply) is all working. It can even give you good evidence as to the clock rate that your microcontroller is running (something that trips up a great many people,...
Introduction to Microcontrollers - Further Beginnings
Embedded Programming BasicsThis tutorial entry will discuss some further embedded programming basics that you will need to understand before proceeding on to the LED blinky and other example programs. We will do this by looking at the general organization and types of instructions found in most microcontrollers, and how that organization and those instructions are reflected (or, in some cases, ignored) by the C programming language.
Basic CPU...Introduction to Microcontrollers - Beginnings
Welcome to this Introduction to Microcontroller Programming tutorial series. If you are looking to learn the basics of embedded programming for microcontrollers (and a bit of embedded hardware design as well), I hope these tutorials will help you along that journey. These are my first postings here, and I am writing this tutorial series because over the years I have seen countless newbies asking the same questions and tripping over the same stumbling blocks, and I thought I might be able to...
Intro to Microcontrollers Part 2: AVR Microcontrollers
IntroductionThis is part 2 of my playing around with AVR microcontrollers. Last time, I had a basic setup which could program an AVR using the Arduino ISP. I used it to drive a simple 7-segment, multiplexed 4-digit LED display. This is a follow up where I try out some of the other features the ATTiny24A has to offer. I also decided to invest some money in an AVR Dragon programmer/debugger so I'll go over some basic playing and setup with this device. I'll also discuss some of the problems...
MSP430 LaunchPad Tutorial - Part 4 - UART Transmission
Today we are going to learn how to communicate using UART with the Launchpad. For this purpose I will replace the default microcontroller that comes with the board with the MSP430G2553. It is the most powerful device in the MSP430 Value Line and it comes with an integrated hardware UART module, along with 16 Kb of Flash memory, 512 bytes of SRAM and an 8-channel, 10 bit ADC.
UART communication can be useful when dealing with sensors: as a basic example, we could...
MSP430 LaunchPad Tutorial - Part 3 - ADC
In this new episode of our journey into MSP430 I will explain the basics of Analog to Digital Conversion on the MSP430G2231.We will write a program that will read an ADC channel and will toggle some leds based on the result of the conversion.
We start as usual with the inclusion of the header file for the MSP430G2231, the leds stuff and with the definition of a variable that will store the result of the conversion. We also declare a function that will initialize the ADC...
Handling Translations in an Embedded Project
A brief walkthrough on how to handle human language translations in a low level C application. Some options are listed, each with advantages and disadvantages laid out.
Energia - program a TI MSP430 using Arduino sketches
TI MSP430 LaunchpadI started tinkering with microcontroller a couple of years ago with an Arduino Uno. I had a little experience with C, so programming in the Arduino environment has been relatively easy and straightforward for me. My code is not necessarily elegant or efficient, but I can usually figure out how to make an Arduino do what I want it to do eventually. A lot of credit to the Arduino userbase, as it is very easy to figure most things out with a quick Google...
Debugging with Heartbeat LEDs
In this article I’ll discuss one of the most basic debugging tools in an embedded system: the heartbeat LED. Picture this: you’re developing your first program for a new microcontroller. You’ve written the code, configured the programmer, downloaded the HEX file and now... what Your program is running - isn’t it?
Truth is that it’s hard to tell with most embedded software. Compared to desktop or even server applications embedded software tend not to have very many...
Unit Tests for Embedded Code
I originate from an electrical engineering background and my first industry experience was in a large, staid defense contractor. Both of these experiences contributed to a significant lack of knowledge with regards to software development best practices. Electrical engineers often have a backwards view of software in general; large defense contractors have similar views of software and couple it with a general disdain for any sort of automation or ‘immature’ practices. While there...
Introduction to Microcontrollers - Further Beginnings
Embedded Programming BasicsThis tutorial entry will discuss some further embedded programming basics that you will need to understand before proceeding on to the LED blinky and other example programs. We will do this by looking at the general organization and types of instructions found in most microcontrollers, and how that organization and those instructions are reflected (or, in some cases, ignored) by the C programming language.
Basic CPU...When a Mongoose met a MicroPython, part I
This is more a framework than an actual application, with it you can integrate MicroPython and Cesanta's Mongoose.
Mongoose runs when called by MicroPython and is able to run Python functions as callbacks for the events you decide in your event handler. The code is completely written in C, except for the example Python callback functions, of course. To try it, you can just build this example on a Linux machine, and, with just a small tweak, you can also run it on any ESP32 board.
MSP430 LaunchPad Tutorial - Part 3 - ADC
In this new episode of our journey into MSP430 I will explain the basics of Analog to Digital Conversion on the MSP430G2231.We will write a program that will read an ADC channel and will toggle some leds based on the result of the conversion.
We start as usual with the inclusion of the header file for the MSP430G2231, the leds stuff and with the definition of a variable that will store the result of the conversion. We also declare a function that will initialize the ADC...
Coding Step 3 - High-Level Requirements
Articles in this series:
- Coding Step 0 - Development Environments
- Coding Step 1 - Hello World and Makefiles
- Coding Step 2- Source Control
- Coding Step 3 - High-Level Requirements
- Coding Step 4 - Design
If this series of articles has been light on one thing it's 'coding'. If it's been light on two things the second is 'embedded'. In three articles I haven't gotten past Hello World on a desktop PC. That changes (slowly) with this article. In this article I'll...
Using XML to describe embedded devices (and speak to them)
This article discusses one of the typical development cycles in embedded device and communication design and presents a possible, light weight solution using the free DClib/netpp framework.
The challengeAssume we're faced with the design of an embedded device, be it a simple SoC unit or a more complex, uC controlled engine with various attached peripherals. From first prototype to the market, the following development cycle is typically walked through:
Introduction to Microcontrollers - More Timers and Displays
Building Your World Around TimersBy now you have seen four different ways to use timers in your programs. Next we will look at some ways to produce the effect of multiple parallel streams of work in your program with the help of timers. This effect is only an appearance, not a reality, since a single microcontroller (one core) can only run a single thread of code. However, since microcontrollers are so fast in relation to a great many of the tasks to...
Favorite Tools: C++11 std::array
Many embedded software and firmware projects must be developed to high standards of reliability. To meet these reliability requirements, firmware project teams will consider many design tradeoffs. For example, an engineering team may avoid or outright ban the use of dynamic memory allocation, a feature typically accessed via the C library call "malloc" or the C++ allocator "new". When authoring software under such...
Coding Step 2 - Source Control
Articles in this series:
- Coding Step 0 - Development Environments
- Coding Step 1 - Hello World and Makefiles
- Coding Step 2 - Source Control
- Coding Step 3 - High-Level Requirements
- Coding Step 4 - Design
When I first started out in programming, version control was not an introductory topic. Not in the least because it required a 'server' (ie, a computer which a teenaged me couldn't afford) but because it seemed difficult and only useful to teams rather than...
How to make a heap profiler
We'll see how to make a heap profiler. Example code for this post makes up heapprof, a working 250-line heap profiler for programs using malloc/free.
It works out of the box on Linux (tested on "real" programs like gdb and python). The main point though is being easy to port and modify to suit your needs. The code, build and test scripts are at github.
Why roll your own heap profiler?
- It's easy! And fun, if you're that sort of person. What, not reasons enough? OK, how...
Linux Kernel Development - Part 1: Hello Kernel!
Our very first program in every language or framework usually is the notorious "Hello World" program. For this Linux Kernel Modules Development introduction we will follow the same concept, but instead of the usual "Hello World" we will make a "Hello Kernel!" and you will understand the reason in a few moments. Note that in this article I will not focus on a deep explanation about this topic for the moment, since this is only the introduction.
But before we dive into code we need to have the...
C++ on microcontrollers 4 – input pins, and decoding a rotary switch
This blog series is about the use of C++ for modern microcontrollers. My plan is to show the gradual development of a basic I/O library. I will introduce the object-oriented C++ features that are used step by step, to provide a gentle yet practical introduction into C++ for C programmers. Reader input is very much appreciated, you might even steer me in the direction you find most interesting.
So far I...
Arduino robotics #2 - chassis, locomotion and power
Arduino RoboticsBeginner robotics is a series of article chronicling my first autonomous robot build, Clusterbot. This build is meant to be affordable, relatively easy and instructive. The total cost of the build is around $50.
1. Arduino robotics - motor control2. Arduino robotics - chassis, locomotion and power3. Arduino robotics - wiring, coding and a test run4.Coding Step 3 - High-Level Requirements
Articles in this series:
- Coding Step 0 - Development Environments
- Coding Step 1 - Hello World and Makefiles
- Coding Step 2- Source Control
- Coding Step 3 - High-Level Requirements
- Coding Step 4 - Design
If this series of articles has been light on one thing it's 'coding'. If it's been light on two things the second is 'embedded'. In three articles I haven't gotten past Hello World on a desktop PC. That changes (slowly) with this article. In this article I'll...
Embedded Programming Video Course Shows How OOP Works Under the Hood
If you'd like to understand how Object-Oriented Programming (OOP) really works under the hood, here is a free video course for you:
OOP part-1: Encapsulation: This first lesson on Object-Oriented Programming (OOP) introduces the concept of Encapsulation, which is the ability to package data and functions together into classes. You'll see how you can emulate Encapsulation in C, what kind of code is generated, and how to debug such code. Next, you will translate the C design into C++ using...
Debugging with Heartbeat LEDs
In this article I’ll discuss one of the most basic debugging tools in an embedded system: the heartbeat LED. Picture this: you’re developing your first program for a new microcontroller. You’ve written the code, configured the programmer, downloaded the HEX file and now... what Your program is running - isn’t it?
Truth is that it’s hard to tell with most embedded software. Compared to desktop or even server applications embedded software tend not to have very many...
Arduino robotics #3 - wiring, coding and a test run
Arduino RoboticsArduino robotics is a series of article chronicling my first autonomous robot build, Clusterbot. This build is meant to be affordable, relatively easy and instructive. The total cost of the build is around $50.
1. Arduino robotics - motor control2. Arduino robotics - chassis, locomotion and power3. Arduino robotics - wiring, coding and a test run4.