AVR MCU

Introduction to Atmel studio

I assume if you are here to do projects on Atmel studio using embedded c then you are familiar with Arduino IDE. If not then I would recommend you to get familiar with  Arduino IDE because it will build a basic foundation you need to get started. Arduino IDE will make it easy for you to relate variables, functions, etc. How to execute our first code on Atmel studio These are the steps you need to follow to run your first code. Open your Arduino IDe and copy the path I’ve shown below. For this, you need to scroll up. At the top, you will find it. Copy that path and paste it somewhere as I have pasted it in notepad++. You can see I’ve made a few changes in that path you need to do the same.  Now go to tools and open external tools. Here writes the name of the Board you are using as I am using Arduino Uno. Paste the commands in the command section and arguments in the arguments section after making the necessary changes and then click OK.  Now Go to file and create a New Project. Write the name of your program and select the compiler I’ve selected. After selecting the compiler press OK. Here you can see numerous microcontrollers. Now you need to select the one you are using. The microcontroller I am using is Atmega328p. Instead of searching, you can also write it in the search box. It is at the top right corner. Great! Your main.cpp file is open and nowhere you can start programming and making super cool projects. After writing your first program click on build -> build solution. Go to tools and select the External tool title you have saved in point 5). Here to run this code you just need to plug in your Arduino board and make a circuit for blinking LEDs, the same as you must have done while working on Arduino IDE. For reference, you can see the output. CODE #define F_CPU 16000000UL #include <avr/io.h> #include <util/delay.h> int main(void) { DDRB|= (0B00100000); while (1) { PORTB=0B00100000; _delay_ms(1000); PORTB=0B11011111; _delay_ms(1000); } return(0); } /* This is just a demo code so that you can confirm that your code is running properly. For now, you don’t need to worry about the code or what is happening inside. I will share the link down below for the same. */ OUTPUT  

Display Screens I2C Modules Sensors and Modules

SSD1306 OLED Display Screen

Display Technolgy mainly consists of two things: Display Devices and Display Driver Integrated Chips(DDIC). Display Devices: are OLED, LCD, LED, CRT, Vacuum Florescent, etc modules. To know in-depth about the different types of display devices refer to this. Display Driver Integrated Chips(DDIC): are semiconductor IC\’s that provide an interface between the control Unit(MPU and MCU) and a particular type of display device. Display driver accepts commands and data using onboard communication protocols like I2C, SPI, CMOS, RS232, etc and generates signals with suitable voltage, current, timing, and demultiplexing to make the display show the desired text or image. Display driver IC\’s may also incorporate RAM, Flash Memory, EEPROM, and/or ROM. Examples of Display Driver IC are SSD1306, HD44780, KS0108, SSD1815, and ST7920. In this blog, we are going to use the OLED Display device and will go in-depth into one of the OLED Display Driver IC\’s: SSD1306 by Solomon Systech. OLED Display Introduction OLED(Organic Light Emitting Diode) displays are the new technology in the display screen industry that are revolutionizing the user interface for users in various devices like TV screens, Virtual Reality headsets, Smart Watches, and many more. LCD Technology is compentator to OLED technology. LCD is a non-emission and older display technology that requires an external light source to work. While OLED technology is modern and considered to be emission display technology, that does not require a backlight that is an external light source. OLED Display technology is pretty exciting and opens lots of possibilities: Curved OLED Display Wearable OLED\’s Flexible and rollable OLED Transparent OLED embedded in Windows and many more we can not imagine today. The focus of this blog will be more on the understanding of OLED Display Driver IC: SSD1306 and its driver development for operating the below OLED Screen Module. To get to know about the OLED display working and its layers, readers can refer to this blog. OLED Driver IC\’s apart from SSD1306 are SSD0323. SSD1306 OLED Driver IC SSd1306 is an integrated chip that is used to drive the OLED display of the dot-matrix graphic display system. These IC\’s comes in Chip on glass or Chip on Film packaging i.e chip die is directly mounted to a piece of the glass display. SSD1306 has a feature to drive up to 128 columns & 64 rows of OLED pixels. It has constant control, display RAM and oscillator inbuilt which reduces the external components and power consumption. SSD1306 IC itself require only 1.65 to 3.3 V that can be provided to it easily from MCU. But as OLED displays does not have backlight as LCD has, so the panel of OLED requires higher voltages of about 7-15 V which is supplied to OLED panel from internal voltage doublers and charge pump circuitry\’s. And on an average OLED display consumes only 20mA current. Now coming to the part that how does these Driver IC display data on these OLED screens.

IoT Modules Sensors and Modules UART Modules

HC-05 Bluetooth Module

Table of Contents In our era, people are more likely to use wireless devices because it makes using them much easier. HC-05 is a Bluetooth module used for wireless communication. It uses Serial communication to communicate. Its work is based on UART. Usually, it is used to connect small devices like a mobile phone or laptop and exchange files over the range of less than 10m. You can also communicate  between two microcontrollers like Arduino through this. However, this module does not transfer multimedia like photos or songs. It can take up to 4-6V of power supply. It supports baud rate of 9600, 19200, 38400, 57600, etc.  Refer to these blogs if you feel stuck. Serial Communication UART HC-05 Default Settings Specifications How to connect HC-05 module HC-05 Module PIN OUT of HC-05 Connection or HC-05 & Arduino Modes of Communication Data Mode: This mode is used to communicate with other Bluetooth devices wirelessly. Command mode: AT Command mode is where we can change the default device settings. Let\’s see an example here for both of the modes, starting with Data Mode. Bluetooth communication between Devices (Data Mode) Here we will connect our module with Arduino and our phone. We will send signals from the phone to the HC-05 module wirelessly which will be displayed on the serial monitor. If we will send 1 it will turn on the LED or If we will send or it will turn off the LED.  Components required: Arduino Uno LED Jumper wires HC-05 Bluetooth An android phone Steps. Follow the steps mentioned above to connect your module. Now follow these steps to make the circuit turn on/off the LED. Connect the long leg of the led with the resistor. The resistor should be connected with any digital pin, let\’s say pin 13. Connect the short leg with the ground. 3. Now we are using the same TX, RX pin for communication. For this, First, we need to remove RX, TX wire. We did this because Arduino Uno has only 1 pair of UART pins and by them, it receives the data from the IDE. We are aware that Arduino uses the UART protocol for communication. If we connect these pins with the HC-05 module while uploading we will get an error as it will clash. Upload the code to the Arduino and reconnect the pins. int ledP=13;int dtime=1000;int readData;void setup() {  // put your setup code here, to run once: pinMode(ledP,OUTPUT); Serial.begin(9600);}void loop() {  // put your main code here, to run repeatedly:while(Serial.available()==0) {} // reading the data from the serial monitorreadData = Serial.parseInt();Serial.println(readData);if(readData==0){  digitalWrite(ledP,LOW);}if(readData==1){  digitalWrite(ledP,HIGH);} To send the signals via phone we need to install an app. I use an Arduino Bluetooth controller. Pair it, add the password which is usually 1234 or 0000. Changing the default settings of HC-05 (Command mode) AT Command mode is where we can change the default device settings. Steps to use AT commands Connect your Arduino Board to the Pc. Upload the bare minimum code to Arduino without any breadboard connection. Unplug the Arduino from the computer. Connect the HC-05 module to the Arduino as below. Press and hold the push-button on the module for 1-2 sec and while holding it connect the Arduino to the PC. Now you’ll see the red light will blink in 1-2 sec intervals which shows AT command mode is active. Now select the baud rate to 38400. We do that because 9600 is slow for high-speed transmission. It can go even higher according to the HC-05 reference. Set the box next to the baud rate from newline to both NL(newline – n) & CR(carriage return – r). Now we will use AT commands. First, type At on the Serial Monitor and send. If you will see an OK then everything is fine. To change the name of the module we use AT+NAME=HC-05Devanshi. To change the Password of the module we use AT+PSWD=\”9876\”   You can refer to this for AT commands. Applications of HC-05 module Robots  Wireless communication between two microcontrollers Communication with Mobile and Laptop

Embedded Basics Embedded MCU's Miscellaneous

Introduction to the I2C

I2C communication stands for inter-integrated circuits. I2C contains the best features of SPI & UART. It is a synchronous communication protocol. It transmits data serially. It is widely used in microcontrollers, IoT, sensors, displays, and EEPROMs, etc. I2C can be single master multiple slaves and multiple master multiple or single slave. In this blog, we will get to know about I2C in depth. Highlights of I2C I2C works with 2 wires only for communication. SDA [Serial Data]: It is used by the Master and Slave for the transmission or receiving bits. SCL [Serial Clock]: It is used to carry clock signals. I2C can communicate with 2 different methods. Slave selection protocol uses a 7-bit slave address. I2C doesn’t have any fixed length of data transfer. Confirmation after transferring every byte. Full-duplex. How does I2C work? Start Condition To initiate the communication, the master keeps the SCL line high and pulls the SDA line low. If we have more than one master then the one who pulls the SDA line low first will send the data first and if the SDA line is already low then the other masters can not send the data. Addressing Master sends the same address to all the slaves. The slave then compares its own address with this address. If the address doesn’t match with the slave, the slave doesn’t do anything if it does match then the slave sends an acknowledge bit to the master. Read/Write Bit With the address, master sends the read/write bit to all the slaves where 0 indicates a write and 1 indicates a read. If the master wants to read data from the slave then it sends the read bit. If it wants to write then it sends a write bit. ACK/NACK Bit Each frame in a message is followed by an ack/nack bit. If an address frame was successfully received, an ACK bit is returned to the Master from the slaves. THE DATA FRAME When the acknowledge bit is received by the master, the master sends the data frame to the slave which is of 8 bits. After every data frame the slave sents an acknowledge bit to confirm that the data frame has been received successfully. Stop Condition To generate the stop condition master pulls the SCL from high to low and SDA line from low to high. Applications of I2C Communicating with multiple micro-controller. Accessing low-speed DACs[digital to analog converter] and ADCs[analog and digital converter]. Accessing real-time clocks. Reading hardware sensors. Previous Next

AVR MCU Embedded MCU's

ADC in AVR

Table of Contents Introduction to Analog To Digital Conversion (ADC) Microcontrollers as we know of today are digital devices that is they only understand digital signals but our world is not digital and produces many analog signals as well. Here comes the role of ADC. Analog to Digital converter as the name suggests is used to convert any analog signal to digital so that microcontroller can read that signal. AVR microcontroller have inbuilt ADC on all bits of PORTA. In this blog we will be discussing about all the registers and bits necessary to use ADC on AVR. ADC on AVR Now let us use this ADC of AVR and convert analog signals to digital and read them. Block Diagram for using ADC on AVR: Let us discuss these steps in detail to understand use of ADC in AVR STEP – I : Basic Setup 1) Setting up pre-scalar for ADC frequency We know that digital signal are at fixed moment or instances of time while analog are continuous in time. So when we convert analog signal to digital signal we need to decide that on how many instances of time we need to take value of signal so that we can create a digital counterpart of signal. In the image above the green line depicts analog signal and blue lines make up digital signal. Now we need to decide that for ADC how many blue lines we need. The no. of blue lines in a second is called sampling frequency. AVR has a counter which counts from 0 till 65536 and turns back to 0 and counts again. We will tell AVR that every time you count 16 times then put 1 blue line of digital signal according to analog signal. This thing is known as pre-scalar. If we set up a pre-scalar of 8 means we say to AVR that after every 8 times you count add 1 reading of digital signal. Preferred and generally used pre-scalar value is 16. ADCSRA i.e. ADC Control and Status Register A has bits 2,1,0 which decide the prescalar for ADC. You can refer table below which is taken from datasheet to select value for ADC pre-scalar: Lets see code for setting 16 bit pre-scalar. For 16 bit pre-scalar we need to only set bit ADPS2, so we will set 1 to ADPS2 bit in ADCSRA register. ADCSRA |= (1<<ADPS2); 2) Setting up resolution for ADC Resolution is nothing but a technical term for maximum value that we will be taking up as digital value. As we convert analog signal to digital we convert it to numbers where a number will represent the maximum analog input value i.e. if we set max input to 5v then digital value of all inputs equal to greater than 5v will be that number. Similarly a number is assigned to minimum value and the range between those numbers represent the values between minimum to maximum input voltage set. Now 8bit resolution means 0-255. The question comes up how? It has a simple answers. 8 bit resolution means that the converted value will have 8 binary digits. So now minimum value of 8 digit binary number is 00000000 which is 0 in decimal and highest value is 11111111 which is 255 in decimal hence the 8 bit range is 0 – 255. Here 255 represent 5V (Maximum voltage input) and 0 represents 0V. This makes up 256 digits for 0 volt hence we can calculate: 5V/256 = 0.0195V This implies that every number represents 0.0195 V. So 1 in digital value is equal to 1*0.0195V = 0.0195V. Similarly 25 means 25*0.0195V = 0.4875 V and so on… Similarly 10 bit has 10 digits so range becomes from 0(0000000000) – 1023(1111111111). And now if we select maximum output voltage to be 5V then 1023 means 5V but for every count precision increases, so: 5V/1024 = 0.00488V Hence every count represent 0.00488V and as shown above now 25 count will mean 25*0.00488 = 0.122V. Enough theory!!! Now lets see how to write code and select the resolution (range) we need for our ADC. AVR has a 10bit ADC. We can obtain both 8 bit values and 10 bit values from ADC for AVR. To set resolution we need to use ADMUX register of our microcontroller. ADMUX stand for ADC Multiplexer selection register. For 8 bit mode, set ADLAR bit of ADC to 1. ADMUX |= (1<<ADLAR); For 10 bit mode, clear ADLAR bit i.e. make it 0. ADMUX &= ~(1<<ADLAR); 3) Setting up ADC reference voltage Reference voltage is the voltage level which will be considered as maximum voltage by our ADC and at any voltage level equal to or greater than reference voltage, we will get the maximum value after conversion. The maximum value that we discussed above is same ad known as reference voltage as ADC takes this voltage as reference to work. Reference voltage can be set using ADMUX register. Bit 7 and bit 6 decide the reference that we are going to use according to the following table fetched from the datasheet. a) AREF(00) – We give the reference voltage to AREF pin, i.e. PIN 32. b) AVCC(01) – The reference voltage is considered as power connected to VCC. AVCC is Analog VCC which is optional to give for better ADC functionality. If you leave it empty then also nothing happens. It also suggest to add an external capacitor between AREF and GND so that there is no noise in ADC due to AREF pin. c) Internal 2.56V(11) – This provides a fixed internal reference voltage of 2.56V to ADC. It also has suggestion of adding a capacitor in similar way as above so that there is no noise from AREF Pin. For AREF mode, clear REFS0 and REFS1 i.e. make them both 0 ADMUX &= ~(1<<REFS0); ADMUX &= ~(1<<REFS1); For AVCC mode, set REFS0 ADMUX |= (1<<REFS0); For Internal 2.56V, set both REFS0 and REFS1 i.e. make them both 1 ADMUX |= (1<<REFS0);

Electronics Miscellaneous

What is EMC Emission Testing

Table of Contents These tests are conducted on all electronic/electrical devices and equipment, to make sure they do not make devices next to them malfunction. These tests are those which are conducted to measure the power and frequency of RF emissions from devices and equipment. These emissions are categorized as those under 30MHz and over 30MHz, because of the two primary methods of EM emission from equipment, conducted and radiated. Emission Measuring Instruments Measuring Receiver Conformance tests are taken with receivers which are optimized for the purpose of taking EMC measurements. The average cost of measuring a receiver system between 10kHz to 1GHz range is between $15,000-$60,000. Spot Frequency Receiver- These are hand-held receivers that the operator uses to take readings of emissions of individual frequencies from the EUT. FFT/time Domain Receiver- Fast Fourier Transform is an algorithmic implementation of Fourier Transform that enables the measuring device to take time-domain readings and convert them into real-time frequency spectrum plots. Spectrum Analyzer- This is used to record emissions from the EUT in the full frequency spectrum, within the device’s capability. This is used to confirm the frequency range in which sport frequency reception will be required because due to their full spectrum measurement capability these devices have a small amount of error. Receiver Specifications Figure 1 The new R&S®ESR EMI test receiver uses an FFT-based time domain scan to perform stan-dard-compliant dis-turbance measure-ments up to 6000 times faster than con-ventional EMI test receivers. These are the parameters on which these devices evaluate, emission performance of the equipment under test. These parameters are defined in CISPR 16-1-1, and MIL-STD-461G, and DEFSTAN 59-411 for military tests. Transducers These devices are used to convert the emissions to be measured from the EUT into something which can be displayed onto the screen of the measuring device. These devices are able to convert the four important parameters, Radiated electric field Radiated magnetic field Conducted cable voltage, and Conducted cable current Into readings which can be displayed on the screen on the receiver. CISPR 16-1-4 is referenced while choosing transducers/antennas for EMC emission testing. LISNs and probes for cable measurements Artificial Mains Network.  These devices are used to conduct voltage emissions tests on the main port. These are required to provide a defined impedance at RF across the measuring point, to test the instrument, and isolate the test circuit from unwanted interference signals on the mains supply. Artificial Hand The requirements for this are specified in CISPR 16-1-2. This accessory is used to simulate those devices which are designed for hand-held usage. This accessory is a strip of metal foil, 6cm wide and normally wrapped around that part of the EUT which will be touched by the user’s hand. Absorbing clamp and CMAD These devices are used to measure emissions above 30MHz as radiated fields. The standards used to get this apparatus is CISPR 14-1/EN 55014-1. Current Probe This is a clamp-on device that is used to measure the amount of current flowing in a cable. The standard used for this is CISPR 22/EN 55022. Near Field Probes These probes are used to detect emissions near to culprit device. These devices can be around cylindrical rod or a loop that needs to be taken near the culprit devices to take readings

Electronics Miscellaneous

What is Altium CircuitStudio?

Altium Circuit Studio is an entry-level but professional PCB design suite. Which offers interactive automated routing, intuitive ECAD-MCAD collaboration, integrated SPICE simulations, and unparalleled design efficiency at an affordable price point. Often compared to KiCad because of the small difference in price point. Altium CircuitStudio comes with a perpetual licence fee of $495. With its native 3D, version control and over 300,00 component library and the Altium promise. This software will definitely prove to be better than others in its class. Opening up this software showcases a deliberately minimal interface that requires lesser resources to run on your computer. This showcases the demographic this product is aimed towards. Exactly as it says on the box entry-level professionals or freelancers or undergraduate students. This is not a full-professional product which is made evident by some things like, not being able to multi-object drag and drop, remapping hotkeys (this is a very mouse-heavy program), and no.DbLib support. CircuitStudio is unable to define its place, for a perpetual license fee of $495 you get 90% of the features of Altium Designer but those last 10% are the real challenge, this means that software is limited to designing low-level PCBs, which can be good for a freelance, but the price at which you get this software may just be too high for a graduate student willing to pay $120 per year for the Altium Designer student version, but without the ability to sell your designs, which CircuitStudio offers. The best thing which circuit studio offers at this price point is the Altium component library. This software is a good investment to start your PCB design and schematic journey while getting hands-on lessons and tutorials straight from the Altium community.

BLE IoT

Bluetooth Low Energy (BLE)

Motivation is necessary to reach to our goals but discipline is needed to make them achievable. What is Bluetooth Low Energy? This series of blogs on BLE, is for anyone who is going to start with Bluetooth Low Energy. Bluetooth energy comes under the short range wireless communication protocols of IoT. So lets start by understanding what is BLE. Bluetooth is a wireless communication protocol that is started as a cable replacement technology to replace wires in devices like mouse, keyboards and etc. It operates at 2.4Ghz in unlicensed ISM frequency brand. Their are two types of Bluetooth devices: one is Bluetooth Classic(BR/EDR) and Bluetooth Low Energy. Bluetooth versions from Version 1.0 to 3.0 are referred as Bluetooth Classic and from 4.0 to latest version 5.2 are referred as Bluetooth Low Energy(BLE). Bluetooth protocol is backwards compatible. Bluetooth Classic technology is developed as a wireless standard allowing cables to be replaced connecting portable and fixed electronic devices, but it cannot achieve extreme level of battery life because of its fast hopping, connection oriented behaviours and relatively complex connection. Bluetooth Classic further has Basic Rate mode(V1), Enhanced Data Rate mode(V2) and High Speed mode(v3). In this article we will not dwell much into the Bluetooth Classic, our discussion area will be confined to Bluetooth low Energy. BLE stands for Bluetooth Low Energy, which has been created for the purpose of transmitting very small packets of data at a time, while consuming significantly less power then Bluetooth Classic. Now for working with any wireless communication protocol, their are 2 important concepts that have to be understood for it. Its Communication Protocol Architecture and Communication protocol Stack( it is the firmware implementation of the Architecture). So for proceeding with BLE, we will first understand Its architecture, about the terms like GATT,GAP, HCI and how does Bluetooth low energy works and then further will understand its stack on Nordiac devices. Click here Read more such articles:

Stay Updated With Us