GPIO Modules Sensor/Module Interfacing Sensors and Modules Tech

Implementation of keypad module(4*3) with stm32f103

In the last blog we discussed what a keypad module is . In this blog we will be discussing how to interface a 4×4 membrane type keypad module with stm32 microcontroller. Although the keypad module can be configured using both polling and interrupt methods , in this blog we will be discussing the interrupt method as it takes less CPU cycles , also since interrupt doesn’t require constant CPU attention. Keypad module along with stm32 microcontroller finds applications in industrial machines as well various projects such as bluetooth door lock , scientific calculator etc. Hardware description The keypad module consists of 3 layers:- The top layer is made of polymer which usually is the printed graphic overlay . It defines the function of each button in the keypad module . It is heat and water resistant and also prevents from electric discharge. The middle layer that usually consists  of dome shaped stainless buttons which upon touch makes contact with the bottom layer completing the circuitry. The bottom layer consists of printed circuitry made of conductive material such as silver or copper oxide. When a key is pressed the dome shaped buttons make contact which completes the circuit and this information is conveyed to microcontroller in the form of signal by the external ribbon. The 4×4 keypad module chosen by us consists of numbers from 0 to 9 along with 2 characters ‘*’ and ‘#’ in the first 3 columns while the last column consists of alphabets A, B ,C , D. The internal circuit diagram of the keypad module Internal Circuit Working Circuit Diagram As can be seen one end of each button is connected to a wire that is then connected to the connector pin as row and other end is connected to another wire which is the column wire. Both the row and column wires helps us pinpoint the button that is pressed. The connection are then made to the MCU in which the row part is configured as GPIO output and written high in our case this will be PA15, PB3, PB4 , PB5 pins the column part is then written as GPIO EXTI interrupt  which will get triggered in case of a button push , this will be PB6,PB7,PB8,PB9 in our case .  As can be seen in the figure since each row from one side is already HIGH once the connection is made by pressing the button this is read by the MCU pins PB6,PB7,PB8,PB9 and the interrupt is raised which is detected in the rising edge. Besides the keypad module connection UART1 is also enable as PA9 as TX and PA10 as RX This will be used to display the button pressed when the interrupt is fired using teraterm or similar software. ALGORITHM Configure pins PA15,PB3,PB4,PB5 as output pins with no pull up and low frequency Configure pins PB6, PB7,PB8, PB9 as interrupt pins with no pull up and interrupt detection on the rising edge Set the NVIC priority as 0 and enable IRQ Incoming interrupts are handled using EXTI callback function Initialize the UART1 function , configure the parameters and select PA9 as tx and PA10 as RX Hal tick function is called to use key debouncing and prevent unwanted input noise from the buttons 2 variables currentMillis and previousMillis are declared which prevents extra activations or slow functions from triggering the interrupts this is done by subtracting the former from latter and the difference should be greater than 10 Each row is written GPIO 1 and checked if the corresponding column is gpio 1 as well. in case both the conditions are satisfied the interrupt is raised and a keypress is detected The keypressed is displayed on Teraterm or similar software using UART1 SOFTWARE CONFIGURATION Open the stm32cube ide and configure the sys mode, select the debug as serial wire and time base source as systick . In the GPIO section select the pins PA15, PB3,PB4, PB5 as output pins set parameters to default which is GPIO pins to no pull and operations at low frequency . Next select the pins PB6,PB7,PB8,PB9 as EXTI interrupt pins also in the NVIC section enable the line EXTI line [9:5] interrupts .Also configure the GPIO EXTI as interrupt rising which would read the occurrence of the interrupt on the rising edge of the wave and operation as low frequency . The NVIC priority is set to 0 (the highest) and the IRQ is enabled. All the button or key presses are handled by HAL_GPIO_EXTI_Callback function in which the keydebouncing is applied and each row is written GPIO HIGH incase a button press the respective column goes high as well raising the interrupt and the corresponding key is displayed using UART .for eg-The button press such as key 9 is detected when both PB3 and PB7 is HIGH as due to the press a connection is made and an interrupt is raised. Also in the connectivity section select the UART1 set the parameters such as mode to asynchronous , baud rate 115200, Word-length as 8 bits , Stop bits as 1 , mode as TX and RX , hardware flow control as none and oversampling rate as 16 . The UART1  has pin PA9 as TX and PA10 as RX . The uart is used to display the key that is pressed on a teraterm or similar software with baud rate set to 115200 SOFTWARE CONFIGURATION CODE #include “main.h” #include #include /* Private includes ———————————————————-*/ char buffer[32]={0}; /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef ———————————————————–*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ————————————————————*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro ————————————————————-*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ———————————————————*/ UART_HandleTypeDef huart1; /* USER CODE BEGIN PV */ GPIO_InitTypeDef GPIO_InitStructPrivate = {0}; uint32_t previousMillis = 0; uint32_t currentMillis = 0; uint8_t keyPressed = 0;

Sensor/Module Interfacing Sensors and Modules Tech

Keypad Module in Embedded

Table of Contents What are Keypad Modules ? Keypads are input devices that most of us are familiar with  that help us communicate with a machine , by pressing a set of buttons or keys and giving it a set of instructions to perform tasks.We see them at ATMs, Phones,,military, even Refrigerators , Vending Machines etc constantly evolving and changing over the years such as membrane keypads,dome-switch keypads, capacitive touch keypads etc. Keypad modules are basically sets of buttons , keys or switches arranged in  rows and  columns in matrix form which establishes a connection when a button is pressed and this information is transmitted to the machine.Keypads play an important role in human machine communication be it an operator in a factory or a child buying a beverage from a vending machine . But all these variety of applications of the keypads showcases the different types of keypads and the technologies they employ. Types of Keypad Modules 1. Membrane type Membrane type keypad modules are most commonly used in commercial applications as well as household appliances such as refrigerators , coolers, calculators etc. They are  made of 3 layers : The top layer that consists of labels and printed text justifying the function of that particular key they are made up of polyester or polycarbonate materials hence the printed material lasts for a long time. This is the only layer that is visible to the user.This layer also prevents charge discharge and is water as well as heat resistant. Space layer that comprises the button which is usually made of stainless steel . They usually have a dome structure that helps them make contact with the bottom layer . Bottom layer that consists of the conductive material, usually silver or copper oxide. The parts where there is a chance of short circuit are painted with a dielectric. When the user presses a key the stainless steel button and the bottom layer comes in contact completing the circuitry which is then sent to the external ribbon as a signal . The size of these  layers are as thin as membrane hence the name membrane. Each of the layer is a half of the circuit that is connected to the external ribbon which acts as a communication path between human machine interface. PCB Type The PCB type keypad module consists of a PCB which is designed in such a manner that connections are made between each row and column on which mechanical push buttons are soldered . The connections between rows and columns are then finally ended on the 8 connector pins which are connected to the machine to identify the location of the button pressed.These can be customized as per the need. They are widely used in the phones and cheaper , easy to install and have a relatively long life. Capacitive type The capacitive touch type keypad module as the name implies uses the change in capacitance upon application of the touch as a measure to detect the human interface  . The human finger acts as a dielectric which increases the capacitance . This increased capacitance causes an increase in the charging and discharging time which is monitored and classified as touch. These are often used over their counterparts such as resistive type which are slower and less smoother.Since change in capacitance is involved these modules are also sensitive high levels of heat , light , temperature changes, liquid application  etc. To counter the behavior  of touch keypad modules under the exposure to the liquid the texas instruments keypad module uses mutual capacitance rather than self capacitance to classify a touch and distinguish false touches. Dome Switch  It’s a combination of a flat-panel membrane and mechanical-switch keypad. They feature two circuit board traces embedded under a silicone keypad with a dome-shaped switch. These domes create tactile feedback when pressed, making them particularly useful in commercial and work-related applications. Furthermore, dome-switch keypads have a high level of reliability, often lasting for as many as 5 million cycles. Scissor switch type In this keypad module the keys are designed like scissors. They also have a rubber dome key such as in dome switch but they have improved functionality  by keeping the keys connected together . They may have better functionality but they tend to be expensive and are high maintenance. They are different Scissor Switch type in the market but in general they have 3 layers. 4 x 3 The 4×3 keypad module as the name suggests consists of 4 rows and 3 columns . Even though as per the requirement the size of the matrix can vary in general the 4×3 are used in industry applications in which only numbers are required to be entered in the machine.Hence the first 3 rows consists of the numbers between 1-9 whereas the last last row consists of *,0,#. 4 x 4 Besides 4X3 the 4×4 keypad is also available in which there are 4 columns and 4 rows. In this besides the numeric values alphabets A, B , C , D are also available in the last column . This keypad module finds application in the security system , industrial control system applications, data entry systems etc. How does Keypad Modules works ? The module usually consists of graphic overlay the part of the module that is visible to the user, It is usually made of polycarbonate or polyester materials that are highly customizable depending on the requirement . The material used makes the printed character to last longer. It also consists of  an internal polymer layer which house the internal circuitry and protects from electric discharge and is also heat and water resistant  Inside the polymer layer is the button mesh layer usually made of stainless steel dome like structure and second layer of embossed circuitry usually made by printing copper or silver oxide with some dielectrics to prevent short circuit Both these layers are halves of the internal circuitry that completes the circuit when the user presses the button

NFC/RFID Sensors and Modules

RFID reader module: MFRC522

So, hello to all viewers and welcome back to Gettobyte Platform. In This blog you are going to know about RFID Reader MFRC522, which is designed by NXP Semiconductors. Objective would be to interface this module with Host MCU’s like of NXP Semiconductors, STMicroelectronics or other vendors MCU’s. Will make the driver to interface the RFID Reader with any MCU, not unlike just with Arduino and Arduino IDE environment. To make the driver of RFID reader at first, we need to dig into its datasheet, to understand its various sub parts. And that’s all about this blog is gotten going to be, to make the datasheet understand in easy way-out. Table of Contents Next & Previous Blog Previous Blog: What Is RFID TEchnology RFID Reader MFRC522 Interfacing with Host MCU RFID Technology RFID modules is a wireless sensing technology which is used to track/identify/monitor the objects.  Viewers can refer to this blog to know about RFID technology in detail. or can watch this video which is in animated format to know about RFID technology. MFRC522 RFID Reader/PCD MFRC522 is a highly integrated reader/writer IC for contactless communication at 13.56 MHz. These reader supports the ISO 14443 A protocol for communicating with RFID Tags. They are used to detect the MIFRAME RFID tags. MFRC522 has internal RF transceiver, which provides a robust and efficient implementation for demodulating and decoding signals from MIFRAME compatible cards using ISO 14443 A protocol. The digital module of MFRC522 manages the complete ISO/IEC 14443 A framing and error detection (parity and CRC) functionality. MFRC522 supports 3 tags of MIFRAME family, that are MF1xxS20, MF1xxS70 and MF1S50 products. MFRC522 features MFRC522 though quite old RFID reader and in today’s time many new advance RFID readers have come up. But so as to get started with this technology as a hobbyist/student/DIY project, it is perfect module to lay your hands on this Technology. MFRC522 has highly integrated analog circuitry to demodulate and decode responses when RFID tags are brought in close proximity of these devices. RFID readers are connected with some host MCU, where the processing of data which is received via RFID tags happens according to the application. MFRC522 can connect with host MCU, using SPI, Serial UART and I2C -bus interface. It supports ISO 14443 A protocol and can be used with MIFRAME family of RFID tags. And in MIFRAME family it supports only MF1xxS20, MF1xxS70 and MF1xxS50 products. It has internal CRC-coprocessor. Internal FIFO buffer which can handle 64 bytes of sending and receiving. It uses the Crypto-1 cipher for authenticating. It supports Internal oscillator for connection to 27.12 MHz quartz crytsal. It is low power device, need 2.5 V to 3.3 V power supply. It also has flexible interrupt modes when some RFID tags are detected and trigering events too. In addition to flexible interrupt, it has programmabe I/O pins and timer. It can perform Internal self-test too. MFRC522 Functional description MFRC522 Functional Descriptions MFRC522 Host Interfaces MFRC522 Interrupts MFRC522 Time Unit MFRC522 FIFO MFRC522 CRC Host MCU to MFRC522 Command Set MFRC522 to PICC command set MFRC522 Host Interfaces MFRC522 Host Interfaces MFRC522 can be connected to Host MCU using 3 serial protocols: UART, I2C or SPI. MFRC522 checks the current host interface type. automatically after performing a power-on or hard reset. The MFRC522 IC identifies the hostinterface by sensing the logic levels on the below pins after the reset phase.  The MFRC522 is equipped with a series of registers that allow the Host MCU to access its functional description blocks. To ensure the proper functioning of the MFRC522, the Host MCU must initialize and configure these functional blocks by sending the corresponding register addresses. Each register is essentially an address byte that is transmitted from the Host MCU. Depending on the function described in the register section, read/write operations are performed on the corresponding address byte. It is crucial to properly initialize and configure these functional blocks to ensure the optimal performance of the MFRC522. By understanding the purpose of each register and its corresponding function, the Host MCU can effectively communicate with the MFRC522 and achieve the desired results. –> MFRC522_write_register() –> MFRC522_Read_register() MFRC522 Interrupts MFRC522 Interrupts MFRC522 can trigger the interrupts, when certain events occur. There are 8 events as shown in below table when interrupt can be triggered. When above event occurs, IRQ pin is used to interrupt the host. IRQ pin signal is asserted and host MCU can use its interrupt handling capabilities (basically NVIC if we are talking about ARM based MCU) on what to do when corresponding interrupt has occurred. Status1Reg Register IRq bit is used to indicate if any interrupt source has been triggerered. Status1Reg register IRq bit Which interrupt has been triggered is indicated by ComIrqReg and DivIrqReg Register.  ComIrqReg Register DivIrqReg Which interrupts to be configured and behavior of IRQ pin is configured by ComIEReg and DivIEReg Register. ComIEnReg DivIEnReg MFRC522 Time Unit MFRC522 Time Unit There is a Timer unit in MFRC522, that is used for multiple purposes. Timer unit is essential for maintaing the configuring the clock and analog interfaces. Also timer unit can be used for following features: Timeout counter Watchdog counter Stopwatch Programmable one shot Periodical trigger Timer has an input clock of 13.56 MHz derived from the 27.12 MHz quartz crystal oscillator. The timer consists of 2 stages: prescaler and counter. The prescaler(TPrescaler) is a 12-bit counter. That can be configured using TModeReg register’s TPrescaler_Hi[3:0] and TPrescalerReg register’s TPrescaler[7:0] bits. The Reload value for the counter is defined by 16 bits between 0 & 65535 in the TReloadReg register. The current value of the timer is indicated in the TCounterVAlReg Register.  MFRC522 FIFO MFRC522 FIFO FIFO overview The MFRC522 contains an internal FIFO buffer of 64 bytes, which is equivalent to 8 x 64 bits. This buffer is utilized for both input and output data streams. The host MCU has the capability to perform both Read and Write operations on this FIFO. The host MCU

NFC/RFID Sensors and Modules

What is RFID technology? Applications, Working Principal, Types, Projects

Table of Contents What is RFID technology? RFID is a technology by which objects can be tracked and identified using electromagnetic fields. RFID stands for Radio Frequency Identification. An RFID system consists of an RFID reader known as a Proximity Coupling device (PCD) and RFID tags known as Proximity Integrated Circuit Cards (PICC). RFID Tags are attached to the objects which need to be tracked/identified and each tag has a unique value hard coded. RFID readers are attached to the main system/computer where all the processing takes place. Now, these tags are brought in close proximity to the RFID readers, RFID readers decode the value and send the information to the main system for tracking/identifying/monitoring purposes depending on the application. RFID technology is similar to a barcode or the magnetic stripe of a credit card, as the data encoded in the label or magnetic strip can be captured by a device and stored in a database. RFID belongs to a group of technologies referred to as automatic identification and data capture (AIDC). AIDC methods automatically identify objects, collect data about them and enter the data directly into systems with little or no human intervention. RFID methods use radio waves and automation technologies to accomplish all of this. This technology has grown a lot since its first application. It has not only been improved over the years but also the cost of implementing and utilizing it continues to minimize, making this technology more efficient and affordable. In its simplest form, an RFID system consists of 2 components: an RFID tag and an RFID reader. Refer to the section below to know more in-depth about RFID tags and Readers. RFID tags are used to track objects, by reading/writing information on them and are usually composed of an integrated circuit, antenna, and battery. The integrated circuit stores the data and powers the antenna, allowing it to be read by a reader. Tags contain digitally encoded information that is stored in the integrated circuit and is transmitted to the reader. Readers are devices that intercept, decode, and interpret the information stored in the tag. Typically, readers consist of RFID antennas, multiple operating modes (active and passive), frequency capabilities, and signal processing. The readers, antennas, and tags work together to collect data from RFID tags and transmit it to computer systems. RFID Reader (PCD) PCD(Proximity Coupling device): Also known as RFID readers. They decode the RFID Tags and communicate with them based on ISO14443 standard. PCD can perform read and write operation of data i.e bidirectional communication once PCD and PICC are coupled together. The coupling between PCD and PICC is based on inductive coupling (Refer to Working principle of RFID technology to know physics behind it).PCD energizes the PICC by coupling with them when PICC comes in close vicinity of PCD.And PICC gets energized, it starts transmitting its radio signals with UID of it. For energizing the PICC, they need to be brought in close proximity so that PCD magnetic fields get properly coupled with PICC. PCD’s have the memory(FIFO buffers, EEPROM), communication pins for Host Interface(I2C,SPI,UART), antenna for generating of radio signals, power supply, I/O pins(Interrupt and Timer pins), small CPU for processing of data(CRC,Interrupt controller, Timer unit), Analog interface for RF front head(oscillators, PLL, PGA and etc), Low power modes and support of multi protocols for decoding tags. PCD has the crypto features also implemented inside them, so that only authenticated RFID readers can communicate with PICC. And this also becomes the distinguishing feature in different PCD’s. Like NXP semiconductors, RFID readers follow the crypto-1 cipher for authenticating. Also some PCD’s have secure models and key handling capabilities for secure communication between PCD and PICC for banking and transaction related applications. There are many semiconductor companies who provide the RFID reader chips, with many enhanced features.NXP semiconductors and STMicroelectronics are world leaders in providing RFID reader chips. NXP semiconductors has a family of RFID/NFC chips with many enhanced features. For more indepth knowledge on PCD, viewers can refer to:Radio-frequency identification – Wikipedia. In the upcoming blog, we are going to interface NXP semiconductors MFRC522 and PN512 with host MCU. By making its device driver and to showcase the working of PCD’s RFID Tag(PICC) PICC (Proximity Integrated Circuit Card): These are the RFID Tags, which are known as Proximity Integrated Circuit cards, in technical terms. PICC are attached to the objects which need to be tracked. PICC consists of an antenna for generation of radio waves and memory for storing the UID and other information of PICC. Each PICC has a Unique value hardcoded inside them. This unique value is referred to as UID. The UID value is 7 bytes. PICC have memory divided in terms of blocks and sectors for storing the important information. There are mainly 2 types of PICC/RFID tags. Active tags and Passive tags. Active tags: They have on chip batteries; thus, they can operate at bigger distances and can operate at higher frequencies. Passive tags: They don’t have an on-chip battery, instead they get energized and get the power from the PCD’s.magnetic fields. Thus, Passive tags need to be brought in very close proximity to PCD of about 1-2 cm, for decoding its value. Also, tags are available in many different shapes, depending on the application. They come in credit card-based shapes, to small key ring-based shapes. Also, some tags have crypto features inside them for authentication purposes when PCD’s communicate with them. NXP semiconductor is a world leader in providing RFID Tag chips. Their MIFRAME family of RFID tags has been implemented in 1000’s of devices and use cases. PCD and PICC communicate with each other according to ISO14443 spec. There are certain commands specified in that protocol, which are at first transmitted by PCD’s and then corresponding PICC responds, and the communication session is initialized. For more in-depth knowledge on PICC, viewers can refer to:Radio-frequency identification – Wikipedia. NXP semiconductor is a world leader in providing RFID Tag chips. Their MIFRAME family of RFID tags

Embedded MCU's Kinetic Sensor/Modules Sensor/Module Interfacing Sensors and Modules SPI Modules STM32 MCU's STM32F1

Implementation of MPU6050 with STM32

In the last blog I talked about the basics of MPU6050, this time let’s see how to interface it with the STM32 based controller and get the values of accelerometer and Gyro sensor. But before  starting first, let’s see the I2C block and the STM32 I2C block to get some idea of the basic structure of the I2C protocol. Figure 1: I2C Hardware Circuit The above circuit diagram shows the hardware connection of the I2C protocol in open drain configuration. The external pull up resistors are being used to make the circuit work efficiently. These days the controllers come with the internal pull up resistors so while writing the code for the same these resistors can be pulled up in the configuration. Before proceeding further lets understand certain terms like pull up, pull down, open drain etc. While using an I/O pin, in the digital domain it has values as LOGIC 1 (HIGH), LOGIC 0 (LOW) and Z-STATE (HIGH IMPEDANCE or FLOATING or TRI-STATE). The purpose of pull up and pull down is to maintain these states of the pin while working. PULL-UP means that the pin is internally connected to the power supply via a resistor and is read as LOGIC 1. PULL-DOWN means that the pin is internally connected to the ground via a resistor and is read as LOGIC 0. In between the two in the configuration, when the pin is neither pull-up nor pull-down and the analog value cannot be represented in the logic value, this state is termed as Z-STATE where there is a floating value.    Figure 2: Pull-up and Pull-Down Configuration Now let’s understand the Push-Pull and Open Drain configurations. PUSH-PULL Configuration: This configuration consist of a pair of complementary transistors which works as: For LOGIC 0, the transistor connected to the ground is turned on to sink an electric current from the external circuit. For LOGIC 1, the transistor connected to the power supply is turned on, and it provides an  electric current to the external circuit connected to the output pin. The slave address of the MPU-6050 id 0b110100x, a 7-bit long. Here the LSB bit i.e.x in the 7-bit long address is determined by the logic level at AD0 pin.If x=0 i.e., pin AD0 is Logic LOW otherwise Logic HIGH. Figure 3: Push-Pull Configuration   Figure 4: The Logic 0 and 1 for Push-Pull Configuration   OPEN-DRAIN Configuration: This configuration consist of a single transistors which works as: For LOGIC 0, the transistor connected to the ground is turned on to sink an electric current from the external circuit. For LOGIC 1, it cannot supply any electric current to the external load because the output pin is floating, connected to neither the power supply nor the ground. Hence the Open-Drain has two states LOGIC 0 (LOW) and LOGIC 1 (Z-STATE). This configuration use external pull up resistor. Figure 5: Open-Drain Configuration   Figure 6: The Logic 0 and 1 for Open-Drain Configuration I2C Let’s analyze the functional block diagram of the STM32. As shown in the figure, the I2C protocol consists of SDA and SCL lines along with an additional pin SMBA used in SMB protocol known as System Management Bus. The figure shows that there is a single Data Register along with the single Shift Register as the protocol is half -duplex. The address block is also there and a comparator to compare the addresses. The control logic consists of Control Register (CR 1 and CR2) and Status Registers (SR1 and SR2)  along with the Clock Control Register for generating the clock for the communication. Figure 7: I2C Block Diagram I2C Implementation Of Figure 9: Pin Connections Above is the pin connection of the MPU6050 with the STM32F411CE. Now set up the stm32 environment as follows: Step 1 Step 2 Step 1 Set up the RCC ad the SYS in the STM32Cube IDE as shown: Step 2 Now enable the I2C1 in the standard mode. Now starting with the code create a mpu6050.h file in the Inc folder and mpu6050.c file in Scr folder. We are all done. Let’s start with the code. In total there are around 80 registers in the IC but during the code all the registers are not required there are certain sets of registers which we are going to use which we will be defining in the header file mpu6050.h. These registers are: Name of the Register Address of the Register (Hex) Function REG_MPU6050_ADDR 0xD0 It is the device address for the MPU6050 module REG_SMPLRT_DIV 0x19 This register specifies the divider from the gyroscope output rate used to generate the Sample Rate for the MPU-6050. REG_GYRO_CONFIG 0x1B This register is used to trigger gyroscope self-test and configure the gyroscopes’ full scale range. REG_ACCEL_CONFIG 0x1C This register is used to trigger the accelerometer self test and configure the accelerometer full scale range. This register also configures the Digital High Pass Filter (DHPF). REG_ACCEL_XOUT_H 0x3B These registers store the most recent accelerometer measurements. REG_TEMP_OUT_H 0x41 These registers store the most recent temperature sensor measurement. REG_GYRO_XOUT_H 0x43 These registers store the most recent gyroscope measurements. REG_PWR_MGMT_1 0x6B This register allows the user to configure the power mode and clock source. It also provides a bit for resetting the entire device, and a bit for disabling the temperature sensor. REG_WHO_AM_I 0x75 This register is used to verify the identity of the device. The contents of WHO_AM_I are the upper 6 bits of the MPU-60X0’s 7-bit I2C address. The least significant bit of the MPU-60X0’s I2C address is determined by the value of the AD0 pin. The value of the AD0 pin is not reflected in this register. Apart from these registers we have two structures and the function definitions that we are using in the main file. Lets now jump directly towards the mpu6050.c file and see how things are working. In this phase, keep in mind the 3 things. Initializing the mpu6050. Read the RAW values of accelerometer and gyroscope Convert the RAR values to ‘g’ and ‘dps’ for Accelerometer

Kinetic Sensor/Modules Sensors and Modules

INTRODUCTION TO MPU6050IC

Most of us are fans of Video Games. We played a lot of games on our mobiles like PUBG, Call Of Duty and my personal favorite Asphalt. In all these games one thing we all notice is that as we rotate or bend our phone, the car also rotates in the same direction.  Have you ever imagined how this would happen? Well their are electronic sensors:  accelerometer and Gyroscope Lets dive into this blog, to know the Ans for this!!! What is an ACCELEROMETER WORKING Let us assume a small ball being placed in a box filled with vacuum and no external force is applied to it (i.e., consider the situation of outer space). Now initially the ball will be at the center of the box. Consider each side of the box as an axis. Suddenly we start moving the box to the left side  with the acceleration of ‘g’ (i.e., 9.8m/s2), the ball will hit the +X side of the box. Since no external force is acting on it, and the entire thing is weightless (vacuum state), hence the force comes out to be ‘g’. Consider another scenario when the box is moved upwards with the same acceleration ‘g’. Now again the ball will hit the downward side of the box i.e. +Z axis with the force equal to ‘g’. This is just a simple explanation on how an accelerometer works but in practical scenario accelerometers are based on MEMS technology built on a silicon wafer with companion CMOS electronics through wafer-level bonding. Taking the above situation in mind, there consists of a silicon wafer having polysilicon springs connected with a suspended plate covered with fixed mass around it on the wafer where in between the space, this fixed plate moves. This entire structure reflects the changes whenever acceleration is applied across the X,Y and Z axis. This reflection is reflected by the capacitance change placed in between the fixed masses as the suspended plate moves thus the sensor records this change in capacitance as the final reading. GYROSCOPE WORKING Since the accelerometer measures the linear acceleration, the gyroscope on the other hand measures the angular rotation which is accomplished by Coriolis Effect. Coriolis Effect The Coriolis Effect states that when a mass (m) moves in a specific direction with a velocity (v) and an external angular rate (Ω) is applied, the Coriolis Effect generates a force (F) that causes the mass to move perpendicularly. The value of this displacement is directly related to the angular rate applied. Consider two masses oscillating in opposite directions at a constant frequency. When an angular rate is applied, the Coriolis effect produced by each mass is in opposite directions, resulting in a proportional change in capacitance between the masses. By measuring this change in capacitance, the angular rate can be calculated. The MEMS sensor consists of a proof mass (i.e., it consists of 4 parts M1, M2, M3. M4) that continuously oscillates inward and outwards in the plane, thus causing a coriolis effect. When the structure is being rotated, the Coriolis Force acts on the moving mass causing oscillations in the plane. There are three modes depending upon the axis along which the angular rotation is applied: Roll Mode: When the angular rate is applied at the X-axis Pitch Mode: When the angular rate is applied at the Y-axis Yaw Mode: When the angular rate is applied at the Z-axis What is A MUST HAVE Motion Interfacing one finds in almost every smartphone and tablet. It is a 3-axis gyroscope and 3-axis accelerometer, in total an integrated 6-axis MotionTracking device all in a single small 4x4x0.9mm package. This package size has been achieved by the MEMS (MicroElectroMechanical System) innovation. Coming to some technical aspect of the IC, It comes with a dedicated I2C sensor bus at 400KHz Features 3 16-bit analog-to-digital converters (ADC) each for digitizing gyroscope and accelerometer outputs. Gyroscope full-scale range of 250,500,1000 and 2000 degree/sec (DPS). Accelerometer full-scale range of 2g,4g,8g,16g and On-chip 1024 Byte FIFO buffer which enables the system to read the sensor data in burst and then enter the low-power mode. Lastly, it operates at a power supply voltage range of 2.375V – 3.46V. Features of ACCELEROMETER in MPU6050IC Features of GYROSCOPE in MPU6050IC Features of ACCELEROMETER in MPU6050IC Features of Accelerometer in MPU6050IC The triple-axis MEMS accelerometer in MPU-60X0 includes a wide range of features:  Digital-output triple-axis accelerometer with a programmable full scale range of ±2g, ±4g, ±8g and ±16g Integrated 16-bit ADCs enable simultaneous sampling of accelerometers while requiring no external multiplexer Accelerometer normal operating current: 500µA  Low power accelerometer mode current: 10µA at 1.25Hz, 20µA at 5Hz, 60µA at 20Hz, 110µA at 40Hz Orientation detection and signaling  Tap detection User-programmable interrupts. Features of GYROSCOPE in MPU6050IC GYROSCOPE FEATURES The triple-axis MEMS gyroscope in the MPU-60X0 includes a wide range of features: Digital-output X-, Y-, and Z-Axis angular rate sensors (gyroscopes) with a user-programmable fullscale range of ±250, ±500, ±1000, and ±2000°/sec  External sync signal connected to the FSYNC pin supports image, video and GPS synchronization Integrated 16-bit ADCs enable simultaneous sampling of gyros Enhanced bias and sensitivity temperature stability reduces the need for user calibration Improved low-frequency noise performance Digitally programmable low-pass filter Gyroscope operating current: 3.6mA Standby current: 5µA  Factory calibrated sensitivity scale factor MPU6050 of MPU6050 Block Diagram of MPU6050 IC Gyroscope sensor Accelerometer sensor Digital Motion Processor (DMP) engine Primary I2C Auxiliary I2C Clock Generation Sensor Data Register FIFO Buffer Interrupts Digital Output Temperature Sensor Bias and LDO Charge Pump Gyroscope sensor Three-axis MEMS rate gyroscope sensor with 16-bit ADCs and signal conditioning It consists of three independent vibratory MEMS gyroscopes, which detect the rotation about the X, Y, Z axis. The capacitive change due to Coriolis Effect is observed whenever a rotation is caused about any of the axes. The corresponding signal is then amplified, demodulated and filtered to the corresponding voltage levels that relate to the angular rate. The sensor has an on chip 16 bit ADC to

Motor Driver Sensors and Modules TIMER Modules

HLW8012 AC Energy metering IC: Part 2

Table of Contents In the last blog of HLW8012 energy metering IC, we have got an overview and understanding of HLW8012 IC. So now in continuation to that blog, in this blog, we are going to develop the Application driver for HLW8012. But before preceding with the Application Driver, we will see the hardware setup. At first, we are going to set up the hardware and connections that has to be made for reading the AC readings. Hardware Setup and connections To be honest this is one of the challenging parts which I faced when dealing with energy metering ICs. As being mainly into Firmware and software part, I was not well aware of the electrical and electronics-related terms, concepts and instruments. Though I am from the EEE branch interest since my graduation was more aligned with Firmware. But I also want to learn and understand the electronics and electrical part, in continuation to my Firmware skills. Thus, I thought of using the Energy Metering IC and make the Energy Meter project, as by that have to learn and understand the Electronics/electrical concepts. Energy Metering IC\’s senses the AC voltage and Current, so input to these IC\’s are AC electrical signals. In comparison to other sensors/modules like temperature, Flash memory\’s, gyroscope sensors, display screens etc., in which input is either our environment or values given by us. But in Energy metering or current sensor ICs, for input we need AC load which will be powered by AC power supply. In addition to these we need multimeters, connecting wires and cables for electrical measurement and connections. Hardware Setup AC load Their are 3 types of AC load: Resistive load, Capacitive load, and Inductive load.  There are electrical programmable AC loads, which are actually used in industry for testing and development of Energy Meters. These programmable AC loads can be configured for any type of load. But those are very expensive, to be afforded. So, I started looking for cheap alternatives for all 3 types of AC load. We are going to use resistive load, which will be an AC bulb filament type. AC Source For powering the AC load, we need an AC power supply that will power it. Now while developing the Energy meter and driver for Energy metering IC, I need a variable AC power supply so that I can check the different readings of AC electrical parameters across my AC load. This is one of the first challenges that I faced, which electrical instrument to use, to have a regulated AC power supply. Because AC-regulated power supplies are also quite expensive in comparison to DC-regulated power supplies, which are not affordable to students.  Then I came to know about the Autotransformers that regulate AC power. One can take it analogous to potentiometers, on rotating the knob of them we get variable resistance. Same way in Autotransformers, there is a knob that maps from 0-270V. By rotating the knob, we can get variable AC voltage. Also, the AC signal from Autotransformer is quite stabilized and accurate, so these work great for such small and hobbyist projects. Multimeters  Multimeters are electrical instruments that are used to measure electrical/electronics parameters. Multimeters can measure both AC/DC readings. In this project multimeters would be used for measurement of AC voltage and AC current across our load. 2 multimeters would be used. One is the generic multimeter, which would be connected across the Autotransformer output pins to measure the voltage. Another is the Clamp meter, which would be connected across one of the wires of our AC load to measure the AC Current. The readings which we will get from here would be used to cross verify and check the readings that would be decoded from HLW8012. HOST MCU In our case, I have used the STM32f103-Bluepill as HOST MCU. Logic Analyzer I will also be using the Logic analyzer, for debugging and seeing the PWM digital signals, that would be outputted by HLW8012. STLINKV2 Debugger STLINKV2 will be used as a debugger to program and flash the firmware into our HOST MCU. Hardware Connections Now coming to the connection parts, we can divide HLW8012 into 2 parts, one is the electronics connection that has to be connected with the HOST MCU. Another is an electrical connection that has to be made with AC load and AC supply. At first, we will interface HLW8012 with our host MCU( which in this case is STM32F103-Blue pill). Viewers can refer to this part to understand how HLW8012 and host MCU communicate with each other. HLW8012 has mainly 3 pins CF(Blue), CF1(Green), and SEL(Yellow) pins that have to be connected with HOST MCU. These pins can be connected to any GPIO pins, just have to make sure that those GPIO pins can be configured in TIMER INPUT CAPTURED MODE. The pins at which CF &CF1 pins will be connected are configured as INPUT and the pins at which the SEL pin would be connected are configured as OUTPUT. In my case I have connected : CF1 pin of hLW8012 –> PA8 CF pin of HLW8012 –> PB6 SEL pin of HLW8012 –> PB12 VCC pin of HLW8012 –> +5V pin of MCU GND pin of HLW8012 –> GND pin of MCU I have also connected the Logic analyzer for seeing the PWM signals digitally and the debugger STLINKv2 for flashing and debugging the code with my HOST MCU. Coming to the electrical connection part, the HLW8012 module has 2 couple of green connectors on it. One couple of connectors is connected to Power Supply, in our case power supply is coming from Autotransformer. So it will be connected to the Output terminals of Autotransformer. Generic Multimeter would be. Another couple of connector is connected to the AC load, in our case, the AC load is AC bulb Filament type. Clamp multimeter would be connected across one of the wire of this connection to measure AC current. That is all connection that has to be made and

Current/Power Sensors Sensors and Modules TIMER Modules

HLW8012 AC Energy metering IC: Part 1

Table of Contents So hello guys, welcome back to Gettobyte Once again. Todays blog is going to be on interfacing the Energy metering IC : HLW8012 which is manufactured by HLW Technology.On previous blogs we have developed the application driver   for W25Q SPI based flash memory’s, is time we are going to develop the Application driver for HLW8012. So first question that must come in your mind is that what is Energy Metering IC. Lets first Understand this term. What are Energy Metering Integrated Chips ? Before Understanding Energy metering IC’s their is one term that i would like to get familiar my viewers that is ASIC’s. ASIC’s are Application Specific Integrated Chips i.e. chips which are designed, developed and fabricated for particular applications.  Energy Metering IC’s are one of the ASIC’s. In this case the specific application is that of Electrical Energy Measurement. By the use and emergence of Energy Metering IC’s we can calculate the Electrical Energy parameters like RMS/Instantaneous Voltage, RMS/Instantaneous Current, Reactive/Active/Apparent Power, Energy Consumed, Power loss/dissipation, Power factor, Frequency digitally. Using this electrical Energy Measurements only our monthly electrical energy bill is calculated. These electrical energy parameters play very important role for monitoring and analyzing of Power consumption in our homes, offices, factories, city’s and all such infrastructures where their is use of electricity. These Ic’s are widely used in Energy Meters, Multifunction Meters, Smart Energy meters, Solar Energy control panels, Factory Automation Panels and etc. Energy metering IC’s are designed using the knowledge of ADC, Opamps, Low pass/High pass filters, use of Analog Electronics with Power Electronics, DSP(Digital Signal processing), Signal Conditioning circuits. All these circuits are designed inside the Energy Metering IC’s using VLSI/VHDL. That is where the concept of Application Specific comes in. So when reading the datasheet of Energy Metering IC’s some overview about these terms and terminologies would be beneficial for understanding the functioning of these IC’s. Voltage and current drive the world in every sense. Using these 2 parameters we can calculate all other electrical energy parameters be it reactive power, active power, energy, frequency, power factor and etc. Energy Metering IC’s primarily measures/senses only Voltage and Current by the use of Signal conditioning circuits, ADC, Opamps, Analog Electronics. Further these IC’s calculates all other Electrical energy parameters using DSP, Low pass/High pass filters and etc. All of these things are designed inside the Energy metering IC’s. Input voltage and current to these IC’s are fed depending upon the principal which we are using for sensing Voltage and current. After feeding the Input to these IC’s via one of the above principals, comes the role of above mentioned circuits/units which are designed inside the chips for their efficient functioning and digital accurate readings. Energy metering IC’s which are widely used are of The above listed metering IC’s and their development boards are very expensive, so for my use case i have found out some cheap/alternative Energy Metering IC’s, but their manufacturer are Chinese companies: STMicroelectronics Metering ICSTMP32/33/34 seriesClick HereTexas Instruments Metering ICsClick HereAnalog DevicesADE seriesClick HereNXP semiconductorsClick Here Previous Next HLW8012( the one we are using this blog) HLW8032 BLO937 PZEM-004T module  CS5460 bi-directional energy meter module This is the First string, Second string, Third string of the sentence. General Description of HLW8012 Energy Metering IC HLW8012 is a single phase energy metering IC, which is based on shunt resistor based principal. The HLW8012 module has on board 1 milli-ohm copper-manganese shunt resistor, which acts as a shunt resistor and used to sense the voltage and current. One of the biggest problem with IC, is its datasheet. The datasheet of this IC is in Chinese language, so likely it would be difficult to understand from it. The IC can measure the RMS Voltage, RMS Current, Active power and Outputs these reading digitally in the form of PWM signals. HLW8012 is a good choice for making small and hobbyist kind of projects which requires the measurement of AC electrical parameters. One such project/product that I found, is made on HLW8012. HLW8012 is inexpensive and good alternative to be used in comparison to  other expensive metering IC’s. The module of HLW8012 is very handy and easy to use. It has 4 input terminals: 2 terminals are connected with AC Load and other 2 terminals are connected with AC Power supply. HLW8012 Outputs the Readings of Voltage, Current and power via PWM signals of 50 percent duty cycle, Their are two pins in HLW8012 CF and CF1 which outputs the voltage, current and power readings in a digital PWM square signal, which host MCU can capture using Timer Input Capture mode. The readings are directly proportional to the Frequency of the PWM signal. Every modern MCU has Timer peripheral, which we can configure in Timer Input capture mode. In this mode Host MCU can capture the PWM signals from external world (here our external world is HLW8012). That’s how HLW8012 will communicate with the Host MCU. Features of HLW8012 Energy Metering IC Based on shunt resistor based principal. Can measure current upto 20Amps and Voltage upto 300 Volts Easy interface to Host MCU sends voltage, current and power readings digitally via PWM square signals. Needs +5 volt to operate the IC. Block Diagram of HLW8012 Metering IC PINOUT of the HLW8012 Energy metering IC Pin Number 1 Pin number 1 is VCC (Chip Select), which is used to operate the power the HLW8012 IC. Connect this pin to +5 Volts of the host MCU. Pin Number 2 & 3 Pin number 2 &3 are V1P/V1N, which are Current differential input pins. These pins are connected in parallel to the shunt resistor(See the application circuit below). This connection is already made on the Module of HLW8012. The maximum voltage that can be input to these pins are 43.75mV. Pin Number 4 Pin number 4 is V2P, which is Voltage differential input pin, this pin is connected to  input AC voltage via resistor network of 47k ohms Pin Number 5 Pin

Memory Modules Sensors and Modules SPI Modules

W25Q128JV SPI Flash Memory: Part3

Table of Contents So continuing with the blog series of, W25Q128 SPI based flash memory\’s , in the previous blogs W25Q128JV SPI Flash Memory: Part1 | gettobyte  W25Q128JV SPI Flash Memory: Part2 | gettobyte we have gone through the introduction and overview for W25Q128JV  flash memory\’s. From this blog we are going to start with the Application and Device driver development of W25Q128JV IC. The Driver which i am going to develop in this blog will be generic can be used with any MCU, by just replacing the SPI API\’s. This application driver will be generic and simple one which will be having API\’s to perform basic Operation on this chip. We will be creating the 2 files, header file and source file(.h &.c) for W25Q128JV Application driver. Header file(.h) will be having all the Macros, Typedefs, Enums, Structures  and function declarations. Source file(.c) will be having all the function definitions and local variables to be used in the driver. Header file (W25Q128JV.h) First thing that we are going to do is define the Object like Macro\’s for all the registers of W25Q128JV in the header file(.h) of W25Q128JV. Macros are widely used in Embedded Programming for referring the registers address with the acronym of the Register names, so that it is easy for developer/user to understand the code or using the API.  Like, above if we want to read the JEDECID of the chip, instead of writing 0x9F in the Application code we can pass the Macro JEDECID. (Though we are not going to use all the registers of W25Q128, as in this blog we are just going to make the driver for following features. The Application driver will be having API\’s for reading-writing the data, erasing the data, reading-writing of Status registers, reading JEDEC ID , chip erase and chip initialise.) /* * w25q128jv.h * * Created on: 15-Apr-2021 * Author: kunal */ #define WriteEnable 0x06 #define WriteDisable 0x04 #define Dummybyte 0xA5 #define ReadSR1 0x05 #define WriteSR1 0x01 #define ReadSR2 0x35 //0x35: 00110101 #define WriteSR2 0x31 #define ReadSR3 0x15 #define WriteSR3 0x11 #define Write_Enab_for_Vol_status_regist 0x50 #define ReadData 0x03 #define WriteData 0x02 #define ReadDataFast 0x0B #define JEDECID 0x9F #define UinqueID 0x4B #define SectErase4KB 0x20 #define SectErase32KB 0x52 #define SectErase64KB 0xD8 #define chiperase 0xC7 #define reset1 0x66 #define reset2 0x99 #define read_addr1 0x020000 #define read_addr2 0x030000 #define read_addr3 0x040000 #define BUSY_BIT 0x01 #define WRITE_ENABLE_LATCH 0x02 Next thing in Header file will be the function definitions that would be used for interacting with the W25Q128JV flash memory\’s. void W25_Reset (void); void WriteEnable_flash(); void W25_Read_Data(uint32_t addr, char block[], uint32_t sz); void W25_Write_Data(uint32_t addr, char block[], uint32_t sz); uint32_t W25_Read_ID(void); void W25_Ini(void); void erase_sector4KB(uint32_t addr); void erase_sector32KB(uint32_t addr); void erase_sector64KB(uint32_t addr); void chip_erase(); void Uinque_ID(uint8_t uinque[]); void WriteSR(uint8_t SR_address, uint8_t SR_data); uint8_t ReadSR(uint8_t SR_address); void WaitForWriteEnd(void); Apart from Object like Macro\’s and Function definition\’s their would be 2 additional function like Macro\’s. //For STM32 CUBEMX #define cs_set() HAL_GPIO_WritePin(GPIOA,GPIO_PIN_4,GPIO_PIN_SET) #define cs_reset() HAL_GPIO_WritePin(GPIOA,GPIO_PIN_4,GPIO_PIN_RESET) //For STM32 BareMetal #define cs_set() GPIOA->ODR |= GPIO_ODR_ODR4; #define cs_reset() GPIOA->ODR &= ~GPIO_ODR_ODR4; As we are going to interface the W25Q128JV via SPI peripheral to our MCU\’s, in which MCU would be the Master device and W25Q128JV would be slave device. And in SPI -> Chip Select/Chip Enable pin is used for selecting the slave. Thus these 2 Macro\’s would be used for selecting the slave before the SPI instructions are send ( by using the cs_set()) and then deselecting the slave after the SPI instructions( by using the cs_reset()). Source file(W25q128JV.c) This file would be having all the function declarations of the functions which are defined in (W25Q128JV.h). The 2 most important API\’s which will Send and Receive the SPI commands are: void SPI1_Send (uint8_t *dt, uint16_t cnt) { HAL_SPI_Transmit (&hspi1, dt, cnt, 5000); } void SPI1_Recv (uint8_t *dt, uint16_t cnt) { HAL_SPI_Receive (&hspi1, dt, cnt, 5000); } API\’s Explained for Device Driver of W25Q128JV: void SPI1_Send () This function is wrapper for transmitting the data via SPI. not be used directly in Application driver, but it will always be called by Other API\’s of the driver to send the command to W25Q via SPI. It has 2 parameters: 1) uint8_t *dt –>pointer to store the data that will be transmitted from the Host MCU to W25Q128JV. 2) uint16_t cnt –> Variable that will be storing the size of data that has to be transmitted from MCU to W25Q128JV. void SPI1_Send (uint8_t *dt, uint16_t cnt) { HAL_SPI_Transmit (&hspi1, dt, cnt, 5000); } void SPI1_Recv() This function is wrapper for receiving the data via SPI. This API is also not used directly by the Application Driver, but will be used by the other API\’s of the driver for receivng the data from W25Q via SPI. It also has 2 parameters: uint8_t *dt –> pointer to store the data that will be received from the W25Q128JV. uint16_t cnt –> variable that will be storing the size of data that has to be received. void SPI1_Recv (uint8_t *dt, uint16_t cnt) { HAL_SPI_Receive (&hspi1, dt, cnt, 5000); } void W25_Reset(): W25Q SPI flash Ic\’s come in small package and they have limited number of the pins. Thus W25Q provides the software reset instruction feature. User/Developer can reset the W25Q by sending the specified instructions to W25Q  via SPI. After reset the device will come to its default state and loose all volatile content. Enable reset – 0x66( reset 1 macro) and Reset – 0x99( reset 2 macro)are the instructions that has to be send for generating the software reset. These 2 instructions has to be send in sequence, as any other command after the Enable reset command( 0x66) apart from Reset(0x99) will disable the reset procedure. Once the reset command is accepted it woulfd take approx 30us to reset the W25Q IC. void W25_Reset (void) { cs_reset(); tx_buf[0] = reset1; tx_buf[1] = reset2; SPI1_Send(tx_buf, 2); cs_set(); } void WriteEnable_flash(): In W25Q, before writing to any Page, Erasing any sector/block or performing full chip erase. We have to send the Write enable Instruction via SPI.

Stay Updated With Us

Error: Contact form not found.