Use neural sensors to build smart sensor systems using microcontrollers

Neural networks are a broad topic. But this small example demonstrates how to create a primary neural sensor that takes resistive readings from multiple sensors and multiply it by weight factor and then sum the results. Results are compared to a three-level threshold. Without going too deep into neural networks, we can say that neural cell thresholds are similar to natural biological neurons. For instance, pain levels: itch is a low pain level while burning sensations are combined with cold and warm feelings. Neural sensors can operate in the same way. Let’s take typical neural sensors, which consist of two inputs with some weights and three outputs. Depending on the threshold level that the sum of inputs gives – we have an output signal on three outputs.

Continue reading

Build your own AVR JTAG ICE clone

After unsuccessful attempts to run a few programs which drive peripherals like USART and Timers on Atmega128, I decided to make a JTAG debugger. I hope it will allow me to see what is happening may atmega128 corrupted, or something is wrong with the software or hardware. The most widely used AVR JTAGICE clone is AVR miniICE, which is compatible with the original AVR JTAGICE. AVR JTAG is mainly used for target board debugging in the real world. And of course, you also can program your AVR’s with it.

Continue reading

Function calls and stacking of parameters in embedded systems

Usually, when you write C programs for microcontrollers, you use functions that can be called any time in the main program or another function. The compiler compiles these functions as subroutines. These functions can be called from the main function or other functions – this is called nesting (nested subroutines). If you see the compiled program’s listings, you will see that subroutines are called by using the call or rcall keyword. The argument of this instruction is a subroutine address that will be executed on the next processor cycle. Call instruction also writes return address from function to the stack to continue the program after returning from the function.

Continue reading

Build Piconomic Atmega128 development board by yourself

First of all, I have ordered to make PCB by using a milling-drilling plotter. Of course, I could make the board by myself, but I wanted to save some time and nerves in case of errors. After one week my board was shipped to me: Then I bought all parts needed. One thing that didn’t go well was that I couldn’t get capacitors and resistors in SMD packages 0603, so I used 0805 to lie on the side.

Continue reading

Generate sine wave modulated PWM with AVR microcontroller

This example will show how ease can sinewave modulated PWM modulated using an AVR microcontroller and a few code lines. For this example, I used Atmega8 MCU. All project is set up in VMLAB simulator. To achieve this, I saved a sinewave lookup table in a Program memory (don’t forget to include interrupt.h header file): PWM is generated by using Phase and frequency correct PWM using a 16-bit timer in Atmega8. Modulation is done by updating the OCR1A value with one from the sinewave table when comparing matches. Reading from flash program memory is done simply: The line above is placed inside the output compare interrupt for OCR1A service routine. Resulting signal in scope simulator: Download project Sinewave modulated PWM source code if you want to try it by yourself. This way, you can modulate PWM with any signal shape that is stored in the lookup table. Updated AVRStudio4 project files!

Continue reading

Variables in embedded C programming language

What are variables in the C language? Variables are simple keywords that are defined by the values. Values can be changed. Variables are like a box with some size where values like apples can be put in. So variables can be various forms and sizes, so-called variable types. Variable type is defined by a reserved word which indicates the type and size of variable identifier: unsigned char my_char; long int all_my_numbers; int number; Why do we need variables? The basic answer is that memory is limited, and the compiler needs to know much space to reserve for each variable. The coder needs to specify the variable type and its size by using one of the reserved words from the table:

Continue reading

Two AVR-GCC examples of using AVR 8 bit Timers

Timers are an essential part of microcontrollers. They can be used in many areas starting with simple timed routines to RTOS. The good thing is that timers run independently of the main program flow. Set up the timer counter and let it do its job while your main program runs and does its job. Let’s take the AVR Atmega8 microcontroller. It has two independent 8-bit timers. One is a little simpler which is featured with essential functions like: Single-channel counter; Frequency generator; External Event counter; 10 – bit clock pre-scaler. Another is more advanced where is OCR (output compare register) included, which allows implementing PWM routines. It has the following features: Single Channel Counter Clear Timer on Compare Match (Auto Reload) Glitch-free, phase Correct Pulse Width Modulator (PWM) Frequency Generator 10-bit Clock Pre-scaler Overflow and Compare Match Interrupt Sources (TOV2 and OCF2) Allows Clocking from External 32 kHz Watch Crystal Independent of the I/O Clock Datasheet documents these timers pretty well. Let’s view a couple of examples with both 8-bit timers. The first example is to do a simple task – every time timer overflows, it has to increase the variable value. And this variable is sent to PORTB in…

Continue reading