Arduino and Matlab scope project

Oscilloscope is quite a universal instrument which I would recommend to invest first. Normal bench scope does the job pretty well. I am not a big fan of DIY scopes that are built of microcontroller and LCD or interfaced to PC via the serial interface. You will never get decent sampling and functionality with low-end parts. But in other hand, building such scope can be fun and be a good choice for student projects. prem_ranjan shares his Arduino-based scope project, where he outputs waveform to MATLAB plots. The investment into this project is minimal. O course you could capture signal directly to Arduino analog pin, but op-amp based signal conditioning could make life easier. In the end, here are few features of this scope:

Continue reading

Multichannel ADC using DMA on STM32

Previously we have tried to do a single conversion of one ADC channel. We were waiting for the ADC result in a loop, which isn’t an effective way of using processor resources. It is better to trigger a conversion and wait for the conversion to complete the interrupt. This way, a processor can do other tasks rather than wait for ADC conversion to complete. This time we will go through another example to set up more than one channel and read ADC values using interrupt service routine. How does multichannel ADC conversion works? If we need to convert several channels continuously, we need to set up Sequence registers (ADC_SQRx). There are three sequence registers: ADC_SQR1, ADC_SQR2, and ADC_SQR3 where we can set up a maximum of 16 channels in any order. Conversion sequence starts with SQ1[4:0] settings in ADC_SQR3 register. Bits [4:0] hold the number of ADC channels.

Continue reading

Introduction to MSP430 Interrupts

In this tutorial, we will see a practical way of coding interrupts. Our task for today will be to learn interrupts for GPIO and Timers. In the initial part, we will first look at coding interrupts for the GPIO pins, and in the other half, we will modify this code to add interrupts for timers. By the end of the tutorial, you will have a code that will blink a led using a timer interrupt. However, the blinking frequency will vary if you push a button. In the last tutorial on timers, we saw that we were continuously monitoring the timer flag to check when the timer has overflown. This process is called polling. The only problem with this method is it keeps the processor busy. What if we had another way by which the timer would itself tell the CPU that the timer had overflown? This is where interrupts come into the picture. For example, imagine a scenario where you would always go up to the door to see someone s there or not. This process can be called…

Continue reading

Use fixed integer types to enhance portability

If you have programmed anything with C, you should be familiar with common data types like char, unsigned char, int, unsigned int, long int, long long int, etc. It is tough to tell by the looks of the type how many bytes this variable takes on memory and how it looks in a different system. For instance, in 8-bit AVR-GCC compiler, int is a 16-bit type, while in ARM-GCC, int is 32-bit. So int size is dependent on platform, compiler, and runtime libraries. And switching between systems may trick you if you are not careful enough. You can always check the size of the variable by using sizeof() function. What to do if you need your code to be portable between different systems. Some great libraries could work on any system, including 8-bit, 16-bit, 32-bit, or 64-bit. To avoid this annoying problem, the ISO C99 standard introduced portable data types that are defined in stdint.h header file. If you open this header file of your default compiler tool-set you will find how things are organized. First of all, it checks…

Continue reading

Timers of MSP430

In the last tutorial, we had a look at configuring clocks or internal clocks of the MSP430. Since you are now at a stage where you can set clocks on your own, we can use them to access various functions of the MSP430. All of the major features, such as the ADC, timers, e.t.c, rely upon the clock or the clock speed at which the microcontroller functions. Timers of any microcontroller are special registers that increment or decrement their value automatically. They are an integral part of the microcontroller and are used in almost every project, from basic to complicated ones. A useful feature of the timers of the MSP430 you can use them to achieve a real-time clock, i.e., a delay of precisely 1 sec, provided you use the 32.768kHz crystal supplied to you with the Launchpad. Let’s move onto the technical specification of the timer. If you have referred to the user guide of the msp430 you must have founded out there are two types of timer mainly ‘TIMERA’ and ‘TIMERB.’ An important point to note here is…

Continue reading

Resetting Arduino via serial line

Usually, Arduino boards are reset by using additional DTR line of the serial interface. This becomes a problem when USB-UART adapter doesn’t support DDR line. And you probably read many cases where one or another particular cable won’t work for programming but can be used for simple serial data transfers. Ralph thought that there should be another solution that would allow using any serial cable for programming. He thought that TXD and RXD lines are always available since they are used for data receive and transmission. So why not to use one of those to reset the microcontroller. With three additional discrete, he created a simple circuit that would stand between RXD data line and RST pin. This is simply an RC circuit that would discharge cap during some time. So when data line works in regular operation – RSTin isn’t affected due to slow cap discharge. But when the RST signal is held down for a longer time – the cap is discharged, and then the RST signal is sent. Since he’s done modifications, he also had to make…

Continue reading