ic Related Articles
Stay Ahead with Expert Electronics Insights,
Industry Trends, and Innovative Tips
- Electronic Components
- News Room
- General electronic semiconductor
- Components Guide
- Sort by
- Robots
- Transmitters
- Capacitors
- IC Chips
- PCBs
- Connectors
- Amplifiers
- Memory
- LED
- Diodes
- Transistors
- Battery
- Oscillators
- Resistors
- Transceiver
- RFID
- FPGA
- Mosfets
- Sensor
- Motors, Solenoids, Driver Boards/Modules
- Relays
- Optoelectronics
- Power
- Transformer
- Fuse
- Thyristor
- potentiometer
- Development Boards
- RF/IF
- Semiconductor Information
- Sensors
- PCB
- transistor
Catalog Resistors and Capacitors Electrolytic capacitors Transistor & diode packages Integrated circuit SMD packages Ball Grid Array Small Outline Packages Flat Packages Surface Mount Technology (SMT) is a technique for mounting electrical components directly to the surface of a printed circuit board (PCB). The component that is mounted on the surface of the PCB using surface mount technology is called Surface Mount Device (SMD). SMT has essentially replaced the through-hole PCB manufacturing technology to reduce cost, and increase efficiency and productivity. Since the size of SMD components is very small, compared to through-hole components many more SMD components can be arranged in a given place. Selecting and knowing the right SMD component for your PCB is very necessary. SMD components have standard codes and sizes which as a PCB designer one should know. Kynix offers all sorts of SMD components for PCB manufacturing which can be found here. This article will help you choose the right SMD component from the Kynix library. SMD components come in various packages and sizes to facilitate the automated manufacturing of PCBs. Most of the SMD components are standardized to make manufacturing easy. The most commonly used SMD components are capacitors and resistors. The standards of these components are set by Joint Electron Device Engineering Council. There are different types of packages. When a new package is introduced in the industry, it is named after its initials such as Quad Flat Package (QFP). While some packages have no name, it creates confusion in the industry. Below we have discussed flat chip SMD resistors, capacitors, diodes & transistors, and IC packages. The size of the SMD chip for resistor, capacitors, and some of the diodes is given by a 4 digits code, which represents the dimension of the flat chip either in inches or in millimeters. In the US it is represented in inches while outside the US it is represented in mm. The first two digits represent the length (L) of the component while the last two digits represent the width (W) of the component. While the thickness is also an important factor in manufacturing, it is not mentioned in the 4 digits code, for this, the actual datasheet of the component provided by the manufacturer should be used. Many PCB components such as resistors, capacitors, diodes, FETs, and other transistors are available in SMD. SMD resistors and capacitors, also known as passive devices, come in different sizes. Depending upon the availability of space, soldering capability, and environment temperature, different packages can be used. The names of these packages given in the table below are derived from the size of the components in inches. Resistors and Capacitors Below are the most common size codes for capacitors and resistors. You can find these resistors and capacitors here. S. NoPackageDimensions (in)12010.02x0.01220160.2x0.1632020.02x0.0242040.02x0.0452070.02x0.0763030.03x0.0373060.03x0.0684020.04x0.0294040.04x0.04104060.04x0.02115020.05x0.05125050.05x0.08135080.05x0.1145100.05x0.1156030.06x0.03166060.06x0.06176120.06x12187050.07x0.05198050.08x0.05208080.08x0.08218150.08x0.15228160.08x0.16238300.08x0.32410100.1x0.12510200.1x0.22610500.1x0.52712060.12x0.062812100.12x0.12912160.12x0.163012180.12x0.183112200.12x0.23212240.12x0.243312250.12x0.253414050.14x0.053515050.15x0.053615060.15x0.063715100.15x0.13815750.15x0.753916080.16x0.084016320.16x0.324118120.18x0.124220100.2x0.14320120.2x0.124420180.2x0.184520300.2x0.34622080.22x0.084724090.24x0.094824120.24x0.124925100.25x0.15025120.25x0.125125150.25x0.155226150.26x0.155327250.27x0.255427260.27x0.265527280.27x0.285628160.28x0.165728170.28x0.175828180.28x0.185930140.3x0.146030200.3x0.2 At present most manufacturers can manufacture PCBs with SMD components up to 0603 easily, going below this size to such as 0402 or 0201 is still difficult for the manufacturers, and thus the cost of manufacturing increases if these components are included in the design. Therefore, most of the manufacturers recommend using 0603 components for PCB design. Electrolytic capacitors The electronic industry adopted EIA and IECQ standards for molded tantalum capacitors. These packages are named A, B, C, D, and E. These correspond to different sizes in millimeters. Package height is not included in the size code. EIA codeMetric codeDimensionA32163.2 x1.6 mmB35283.5 x 2.8 mmC60326.0 x 3.2 mmD73437.3 x 4.3 mm Several other electronic devices can not follow any standard because of their unique nature. SMD components like an inductor, transformers, crystals, resonators, and temperature-controlled oscillators require different packages often larger than the standard packages. It is very unlikely that these packages will be standardized because of their unique nature. However, the package must be chosen in a way to make pick and place possible. These capacitors can be found here. Transistor & diode packages SMD transistors and diodes have the same package type. Transistors have three pins while a diode has two pins. The third pin is added to the diode package to keep the orientation right. Diodes are packages that come in different varieties. Some packages follow the standards of capacitors and resistors that we discussed above. Some of the most common diode and transistor packages are SOT-23 - Small Outline Transistor: It is the most common diode and transistor package. It has three pins and measures 3 mm x 1.75 mm x 1.3 mm. It is used for low-power applications.SOT-223 - Small Outline Transistor: This diode package is used for high-power applications. It is bigger than SOT-23. It measures 6.7 mm x 3.7 mm x1.8 mm. It has four pins with which the fourth one is used for heat dissipation. Integrated circuit SMD packages IC packages are found in many packages and can be classified in many different ways. It is very common to hear the terms DIP, SOP, SIP, TSOP, QSOP, MSOP, SOIC, QFP etc. These are the different packages of IC. They can be categorized as. There are three main package types for surface mount integrated circuits: Ball grid array (BGA)Small outline package (SOP)Quad flat pack (QFP) Ball Grid Array Ball Grid Array package has solder balls attached to the underside of the package. Beneath the balls are electrical traces of IC. Ball Grid Array has further the following types. Molded Array Process Ball Grid Array (MAPBGA)Plastic Ball Grid Array (PBGA) Thermally Enhanced Plastic Ball Grid Array (TEPBGA)Tape Ball Grid Array (TBGA)Package on Package MicroBGA. Small Outline Packages Small Outline Package is another IC package in which pins come out from the sides of the IC. The convention used for SOIC or SO package is the name followed by the number of pins used in the package. i.e SO-12 means the IC has 12 pins. Further types of SOP/SOIC are SOJ - Small Out-Line J-Leaded PackageTSOP -Thin Small Outline PackageVSOP -Very Small Outline Package).TSSOP -Thin Shrink Small Outline Package SSOP -Shrink Small Outline PackageQSOP -Quarter-size Small Outline Package Flat Packages Flat IC package have pins arranged on its side in L or J shape. These pins are arranged on the side of the package with the leads coming out. This package further has many subtypes. QFP (Quad Flat Package)TQFP (Thin Quad Flat Package)STQFP (Small Thin Quad Plastic Flat Package)FQFP (Fine-pitch Quad Flat Package),(Low profile Quad Flat Package)VQFP (Very-small Quad Flat Package)ETQFP (Exposed thin quad Flat Package)PQFN (Power Quad Flat Package)PQFP (Plastic Quad Flat Package)QFJ (Quad Flat J-Leaded Package)QFN (Quad Flat Non-Leaded Package)
Allen On 2022-11-29
Overview of switchesMain parameter of switchesSwitch SymbolSwitch DiagramWhat is a toggle switch?How does toggle switches work?Video related to toggle switchesFive ways toggle switch wiringCircuit diagram of toggle switchTypes of Toggle SwitchDPDT Toggle SwitchDPST Toggle SwitchSPDT Toggle SwitchSPST Toggle SwitchLED Toggle SwitchAdvantages and Disadvantages of toggle switchesRocker Switches vs Toggle SwitchesToggle Switch ApplicationsToggle Switch FAQ Overview of switchesA switch is a piece of equipment used to stop current flow in a circuit. Simply put, a switch has the power to complete or disrupt an electrical circuit. To turn a device ON and OFF, every electrical and electronic application makes use of at least one switch.Switches are therefore a component of the control system, and control action is impossible without them. A switch has two possible states: completely ON (by shutting its contacts) and completely OFF (by opening its contacts).A switch establishes a closed conduit for the current to flow when its contacts are closed, which causes the load to draw power from the source. As demonstrated in the figure below, no power is used by the load when a switch's contacts are open. Main parameter of switchesSwitches ParametersVoltage ratingThe insulation materials, contact separation, rate of separation, and general safety considerations are some of the variables that affect voltage rating.Current carrying ratingThe electronics switches' current specifications are crucial since they will only be able to transport a particular amount of current through their contacts.Current switching ratingAn electromechanical switch's current switching rating is typically lower than its current carrying rating. The problem is that forming and breaking contacts creates arcing, and the contacts can only handle so much of it before the wear on the contacts significantly limits the operational life.Switch formatFor every electronics circuit design, choosing the appropriate switch format is essential. Toggle switches, slider switches, rotary switches, DIPs, thumbwheels, and many more are among the many various switch formats. Any switch's selection process includes the format.Number of operationsThere is always a tiny degree of wear as the contacts of a switch move across one another to ensure the best resistance is obtained.Contact resistanceThere is a higher contact resistance than there would be if the conductor were continuous because a switch's contacts are not a continuous conductor but can be broken and rebuilt.Power ratingThe maximum power that the switch can manage while working is indicated by its power rating. Overriding this rating may result in an excessive buildup of heat inside the device, which could lead to the switch failing and create a safety issue.Inductive ratingIf not handled properly, any inductance in a circuit will raise the intensity of arcing at the contacts and shorten the life of the switch. This means that once current is flowing, it is challenging to stop since the inductance will produce significant back EMFs when the current is stopped. This is because any inductance in the circuit will oppose the change taking place.Contact typeThere are two different types of contacts used in change-over type electromechanical: Break before make and Make before break. Switch SymbolSwitch Symbol Switch DiagramSwitch Diagram What is a toggle switch?Toggle switches are electrical switches that be opened or closed using a lever or handle that is moved forward and backward. Toggle power switches and joystick switches are other names for these switches. These switches can be used in any electrical application because they are flexible devices.Since switches are typically manipulated manually, the toggle switch, which functions as a straightforward ON/OFF switch in many electrical circuits, is essential. The toggle switch controls the flow of current from the power source to a device or within a device by use of a lever.Toggle Switch How does toggle switches work?The armature switches the contact into position to start or halt an electrical flow when the switch operator pulls the toggle (the actuator). To put it simply, pushing the toggle can turn a gadget on or off. There are two functions that can be used; a momentary function means that the switch is only engaged when the force is applied. An internal spring mechanism forces the armature to return to its initial position in order to accomplish this. A latching toggle switch, in contrast, keeps the state after being depressed until the toggle is depressed once again to release the switch.The basic toggle switch design is as follows, although being available in various forms and configurations. When the toggle is pulled, an armature (a component conducting electrical current) attached to it moves, adding or removing an electrical contact from a circuit and activating or deactivating the circuit.Even though momentary switches also have an associated spring that will draw the actuator back to its starting point if released, the switch will typically stay in place unless manually pushed again. Video related to toggle switchesVideo Description: Add a switch easily to any household electronics item or automotive project easily by watching this short video. Five ways toggle switch wiringStep One: Look at the instruction about the toggle switchesElectrical setups for the many types of equipment that you might wish to install toggle switches on vary substantially. As a result, no single guide is likely to offer a universally applicable solution. The procedures in this section are intended to serve as general guidance for a straightforward on-off (also known as SPST) toggle switch. They should never take precedence over any installation instructions that came with your toggle switch or the appliance you're placing it into.You can look at the below instruction about the toggle switches:Toggle Switches Instruction Step Two: Your device's supply wire should be cutYou must link your toggle switch to the device's power source in order for it to act as an on-off switch. Cut the supply wire for your device with wire cutters at a spot that will make it easiest to route one or both ends of the cable to the switch. Using a wire stripper, remove about 12 inch (1.3 cm) of insulation from each end of the wire.Cut the supply wire Step Three: If the cable does not reach the switch from either end, add a pigtail.A pigtail is a brief wire piece with both ends stripped, often measuring under 6 inches (15 cm). It can be used as a form of "extender" by being attached to cables that aren't quite long enough to reach your toggle switch.Pigtail connetced to switches Step Four: Connect the supply wire to the toggle switchNow that the device's supply wire has been severed, you must insert your toggle switch so that it can control the circuit's current flow in the middle of the break. The kind of toggle switch you have will determine how you should proceed. Step Five: Test your switchWhen your toggle switch is properly wired, carefully reattach the power to the device and check the toggle switch's operation. You can swap out the panel or housing if everything functions as it should. Congratulations! A toggle switch has been fitted successfully. Circuit diagram of toggle switchThe SPDT toggle switch's circuit schematic is displayed below. A 6V battery, two resistors R1 & R3, two LEDs D1 & D3, and a 21236N switch can be used to construct this circuit.Three terminals, including one input and two outputs, make up this switch. Thus, we can acquire two outputs, the first of which comes from pins 2 (COM) and 1 and the second of which comes from pins COM and 3. In three-way circuits, this switch is mostly used to control electrical appliances from two places.The pins 1 and 3 are connected to D1 (an LED) and D2 (an LED), respectively, in the circuit shown above. When pin 1 is toggled, the D1 LED turns on and the D2 LED turns off. In a same manner, when pin 3 is toggled, D2 LED will turn ON and D1 LED will turn OFF. Consequently, we are able to manage two loads using a single SPDT toggle switch.Toggle Switch Circuit Diagram Types of Toggle SwitchThere are four main versions of these switch designs, each of which has a different combination of throws and poles, such as SPDT, SPST, DPDT, and DPST. Poles of these switches are often the distinct power supply controlled by each switch, whereas throws are the various areas the switch can be used, such as ON & OFF.DPDT Toggle SwitchDPST Toggle SwitchSPDT Toggle SwitchSPST Toggle SwitchLED Toggle Switch DPDT Toggle SwitchDouble pole, double throw (DPDT) toggle switches are used to establish or terminate connections between two conductors and two different circuits. There are six terminals on these switches, and terminals 3 and 4 get the necessary power to drive the loads on the other terminals, which are 1, 5, 2, and 6. Four-way or four-position switches are the names given to these switches.DPDT Switches The six terminals of a DPDT toggle switch are. The toggle switch is represented by terminals 3 and 4. The electricity required to drive the loads on terminals 1 and 5, as well as 2 and 6, is supplied to these terminals. Between terminals 1 and 5, terminal 3 can switch. Therefore, terminal 3, which represents the toggle switch, can switch between operating the fan and operating the motor if a fan is connected to terminal 1 and a motor is connected to terminal 5. The same is true for terminal 4, too. Between terminals 2 and 6, terminal 4 can switch. In this case, terminal 4, which acts as the toggle switch, can switch between the heater and the blower if a heater is connected to terminal 2 and a blower is connected to terminal 6.Two input switches on a DPDT switch can each be connected to one of two terminals. It can therefore use two switches to control four distinct circuits or devices.The circuit for a DPDT toggle switch is illustrated below:DPDT Toggle Switch Circuit Diagram DPST Toggle SwitchThe name "DPST" refers to a double-pile single throw switch, which is used to establish or terminate the connection between two circuit conductors inside a single branch circuit. These switches typically have four terminals that can be used to simultaneously connect and disconnect two pairs of terminals.DPST Switches A 30A DPST switch is used in this wiring layout to connect a 240V AC load appliance (such as a dryer or water heater). The hot wires for 240V are immediately linked to the two pole, single throw switch and the load point as it is illustrated because there is no need to wire the neutral wire. The dryer is directly linked to the ground wire. When turned OFF, the DPST switch will cut both hot wires. Similar to that, while in the ON position, it will join both Hot wires.DPST Toggle Switch Circuit Diagram SPDT Toggle SwitchA single conductor connection with any of two additional single conductors can be made or broken using a toggle switch known as an SPDT, or single pole, double throw. These switches typically have three terminals, which are typically utilized in pairs. Any load must be connected to the first terminal in order to power a specific gadget. To power the loads on Terminals 1 and 3, Terminal 2 receives the necessary power, while Terminal 3 is utilized to connect to any load and turn on any device. This switch can therefore power any of two circuits. Three-way switches are another name for these kinds of switches.SPDT Switches Three terminals make up an SPDT toggle switch. Any load can be connected to Terminal 1 in order to power a specific appliance. Furthermore, any load can be connected to terminal 3 to power any device. The power required to power the loads on terminals 1 and 3 is delivered to terminal 2 at this point. A SPDT switch can therefore operate any of two circuits. It can switch between the two circuits so that various gadgets or circuits can be powered with just a flick of the switch. The circuit for an SPDT toggle switch is illustrated below:SPDT Toggle Switch Circuit DiagramWe link our 9-volt DC power source to terminal 2 in this circuit. The toggle switch at terminal 2 allows us to switch between terminals 1 and 3. A fan is attached to Terminal 1. The DC motor does not operate when the switch is flipped to the left (terminal 1). The DC motor turns on when the switch is flipped to the right (terminal 3), but the fan does not. You can see how we can control two distinct circuits or devices with an SPDT switch in this manner. A double throw switch offers two possibilities. SPST Toggle SwitchSPST, which stands for "Single Pole Single Throw," refers to a device with two terminals, such as input and output. These switches function just like an ON/OFF switch. This switch's primary job is to establish or terminate a connection between a single conductor and a single branch circuit. Once this switch is opened, the circuit will be cut off, stopping any current flow through the load. When the switch is closed, current flows through the load in a similar manner.SPST Switches A SPST toggle switch only has 2 terminals, as you can see. The input is on terminal 1. The output will be at the other terminal. Simple ON-OFF switches are what SPST toggle switches do. They interrupt the circuit when open, preventing current from reaching the load. Current can move across a closed circuit and drive the load. You can see that the DC motor may be started or stopped using this circuit simply as an ON/OFF switch. The circuit for an SPST toggle switch is illustrated below:SPST Toggle Switch Circuit Diagram LED Toggle SwitchToggle switches with illumination operate at 12 volts DC and light up to show the status of your circuit. Add some flair to your switch and control panels by using these lit toggle switches. Our assortment is completed by toggle switches with LED tips, duck bills, and longer handles. Red, blue, green, and amber are the available illumination colors. Toggle switches with illumination are available in an ON-OFF, single pole, single throw design. The switches' connections, which consist primarily of power in, power out, and a ground for the indicator light, are 1/4 inch push-on terminals. The fundamentals of how to wire an illuminated toggle switch are demonstrated in our video.You shouldn't have any trouble wiring an LED rocker switch if you pay close attention to where your ground, power, and acc pins are placed, follow the diagram below (which uses Oznium's LED Round Rocker Switch with a recommended mounting hole diameter of 3/4 inch) :LED Toggle Switch Circuit Diagram Advantages and Disadvantages of toggle switchesAdvantagesDisadvantagesUse of these switches with circuit boards is optimal.While using these switches, a clicking sound will be heard.These switches often have a small footprint, are incredibly sturdy, and are very easy to seal.When compared to rocker switches, these are bigger and bulkier.These switches are effective in controlling electricity.It requires a toggle lock washer.There are small and regular sizes of these switches available.Only low voltage circuits can use it.A lever can be used to extend and operate them.-These switches are energy efficient since they utilize less -These switches are very strong.- Rocker Switches vs Toggle SwitchesRocker switches and toggle switches are the two primary categories of maintained switches. The advantage of having a rocker switch is that you can typically add images, symbols, or even writing to the switch's face to make it more personalized. It therefore especially helpful in situations where function communication is required. Switches that can be sealed easily are perfect for usage with circuit boards. indicating increased resilience against water and dust. enhancing the switch's suitability for hostile conditions.Which switch is best for your project will ultimately depend on its design and environmental factors. From a design standpoint, some people favor the toggle switch's appearance, while others like the rocker switch's more common appearance. Your choice will be influenced by the circumstances. A toggle switch, for instance, may be preferable if the product is for the marine industry because of its IP rating. Toggle Switch ApplicationsThese switches give drivers of cars easy access to headlights, comparable controls, and indicator lights.Conveyor belts, residual current devices, and other industrial and electrical equipment employ these (RCDs).These switches are present in home, commercial, and industrial power outlets.It can serve as the primary switch for industrial machinery like conveyors and packaging machines as well as AC equipment.These switches are employed in switching headlights, logic-level programs, automobiles, and aviation control panels, among other things.Toggle switches are utilized as switching circuits in communications, commercial, and industrial equipment. Toggle Switch FAQOverview and Applications of toggle switchAn electronic on/off switch is a toggle switch. The best purpose for toggle switches is to change the status of system settings and functionalities. To allow users to select between two opposed states, toggles may be used in place of two radio buttons or a single checkbox. What are the 4 types of switches?Single pole single throw, single pole double throw, double pole single throw, and double pole double throw are the four primary categories of switches. The differences between toggle and switchSince they both manage states but not in the same way, we must first distinguish between a toggle button and a toggle switch: Toggle button: Represents an action that changes a state. Two (or more) mutually incompatible states or possibilities that can be switched are represented by a toggle switch. Should a toggle switch be on the positive or negative?Never switch the ground return side; always switch the supply side. You can flip both lines if you're using a twin pole switch, but you must keep the ground line to the chassis intact. More corrosion is likely to occur on the negative terminal. What is a toggle switch?In order to switch an electrical circuit, toggle switches include an operating lever that can be moved up and down or left and right. A "toggle" is a little wooden rod that is used in place of buttons to fasten garments.
kynix On 2022-11-15
IntroductionWhat is RS485?MaterialsMAX485 pinoutHalf duplex operationHere is how the program worksFull duplex operationHalf duplex operation codeFull duplex codeIntroductionIn digital computer communication between two computers can be made using either parallel or serial method. In parallel communication separate line is dedicated for a one-bit information to transfer. This communication is fast and easy, but it requires a lot of wires at least as many as the number of bits need to be sent in parallel. For example, to transfer a 64-bit data from one device to another, 64 data lines will be required which is impractical in embedded systems. The alternative method to transfer data is to use serial communication. In serial communication one bit at a time is transferred from one device to another one. While this method solves the wiring problem it has a lot of other problems such as bandwidth, data lagging, complex protocol, and electrical standards. There are lot of different methods to do serial communication while one method is good in one situation another one is better in another situation. In this article we will discuss RS485 communication protocol which is one of the many available serial communication methods.Materials1MAX485 module2STM32 F401CDU6What is RS485?An industry specification called RS-485 outlines the physical layer and electrical interface for point-to-point electrical device communication. RS485 is the industrial standard for communication that defines the electrical interface and physical layer for point-to-point communication. RS485 is a robust communication system it can support multiple devices on a single bus, works in a noisy environment as well and requires a maximum of 4 lines.RS485 was first developed in 1983 and has since been used in many industrial applications because of its robustness and simplicity. It has the ability to transmit data over long distances while at the same time it is cheap, thus engineers are using it in all sorts of applications such as automotive, manufacturing, and theater spaces. Nowadays almost all motor controllers, VFDs and manufacturing machines will have a port available for RS485.RS485 is actually a standard that defines the electrical characteristics of the transmitters and receivers for communication protocols. RS482 uses two lines usually called A and B which must be balanced and differential. It means that the two lines must have same impedance, nearly same length and must be differential. The key features of RS485 communication are given belowMultipoint operation10 Mbps data transfer rate at 40 feet lengthMaximum cable length is 4000 feetRS485 works both in half duplex as well full duplex mode. In half duplex mode one device can either transmit or receive data at a time. While in full duplex mode, a device can transmit and receive data at the same time. Having more than one device on a bus can cause problem when two or more devices transmit data at the same time. Therefore, software control is necessary to ensure only one device transmit data at a time.RS485 is the physical layer of communication in the OSI model. It means this layer can be used as a base for other protocols such as UART which in most application people use because UART is an asynchronous communication protocol that does not require any clock signal which make it very easy to use. In this article we will demonstrate how RS485 can be used between two STM32 microcontrollers to communicate and exchange data. We will be using MAX485 module which is an easily available RS485 module. MAX485 pinoutRO → Receiver outputRE → Receiver enableDE → Data enableDI → Data inputVCC → Input voltageGND → GroundA, B → RS485 differential linesHalf duplex operationIn half duplex operation either data can be received or transmitted at a time. Both operations cannot be done at the same time. MAX485 has data flow control pins called DE and RE which puts the module in receiver mode or in transmit mode. Making them low puts the module in receiving mode while making them high puts the device in transmitter mode.In CubeMX the microcontroller of our choice is selected which in our case is STM32 F401CDU6. In connectivity UART1 should be enabled with 115200 bps baud rate. Other necessary settings are given below.RCC → Crystal/Ceramic ResonatorSYS → Debug → Serial WireClock Configuration → HCLK → 84 MHzClock Configuration → PLL Source Mux → HSEGPIO A7 is set as outputHere is how the program worksThe setup has two microcontrollers. We will call one side as A and the other side as B. When a user presses the user key on A STM32 microcontroller it will send the information to the B microcontroller via RS485. The receiving B microcontroller will switch on the onboard LED and will responds with an OK message. The OK message will blink the led on A microcontroller twice. Similarly, when the user presses key on B microcontroller it will transmit a message to A microcontroller and turns on the onboard LED and will responds with an OK message. The OK message will blink LED on B microcontroller twice. Similarly pressing the button again will do the same except this time it will turn off the LED.Full duplex operationIn full duplex operation data can be received or transmitted at the same time. Both operations can be done at the same time. In this mode two MAX485 modules will be required at each end and overall, 4 MAX485 modules will be used. It means that the two MAX485 modules will be constantly in receiving mode while the other two will constantly in transmission mode. MAX485 has data flow control pins called DE and RE which puts the module in receiver mode or in transmit mode. We will put the data control pins of two module as high while put the data control pins of other two module low. The configuration is shown below.The program works the same way as it was working in the half duplex mode however, this time the transmitted and received by MCUs at the same time.Half duplex operation code#include "main.h" UART_HandleTypeDef huart1; /* USER CODE BEGIN PV */int8_t R_Data[1] = {0};int8_t T_Data[1] = {69};/* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/void SystemClock_Config(void);static void MX_GPIO_Init(void);static void MX_USART1_UART_Init(void); int main(void){ HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); //Put RS485 module in receiving mode HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); //Turn Off LED pin while (1) { HAL_UART_Receive(&huart1, R_Data, 1, 10); // If button is pressed on the other MCU if(R_Data[0] == 83) { HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); //Toggle LED pin HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); //Put RS485 module in transmission mode HAL_UART_Transmit(&huart1, T_Data, 1, 10); //Send acknowledgment HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); //Put RS485 module in transmission mode R_Data[0] = 0; } // If OK message is receive if(R_Data[0] == 69) { if (HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_13)) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); } else { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); } R_Data[0] = 0; } // Button is pressed if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0)) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); //Put RS485 module in transmission mode T_Data[0] = 83; HAL_UART_Transmit(&huart1, T_Data, 1, 10); T_Data[0] = 69; HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); //Put RS485 module in Receiving mode } } /* USER CODE END 3 */}Full duplex code#include "main.h" UART_HandleTypeDef huart1; /* USER CODE BEGIN PV */int8_t R_Data[1] = {0};int8_t T_Data[1] = {69};/* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/void SystemClock_Config(void);static void MX_GPIO_Init(void);static void MX_USART1_UART_Init(void); int main(void){ HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); //Turn Off LED pin while (1) { HAL_UART_Receive(&huart1, R_Data, 1, 10); // If button is pressed on the other MCU if(R_Data[0] == 83) { HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); //Toggle LED pin HAL_UART_Transmit(&huart1, T_Data, 1, 10); //Send acknowledgment R_Data[0] = 0; } // If OK message is receive if(R_Data[0] == 69) { if (HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_13)) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); } else { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); } R_Data[0] = 0; } // Button is pressed if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0)) { T_Data[0] = 83; HAL_UART_Transmit(&huart1, T_Data, 1, 10); T_Data[0] = 69; } } /* USER CODE END 3 */}
Victoria On 2022-10-26
Keypads are input devices that are being widely used in many embedded system projects. It can be found in appliances, door locks, and industrial machines. Keypads are used to take input from the user in the form of numbers or characters which can further be used for processing such as password, menu selection and navigating among different options. One of the most common and low-cost keypads is the matrix keypad with 4×4 or 3×3 buttons. In this article we will discuss how a low cost 4×4 matrix keypad can be used in STM32. Before proceeding further, we will need to know few things.Materials14×4 matrix keypad2STM32 F401How a 4×4 keypad works? 4×4 keypadIn microcontrollers usually a pin is used to take input from the user. This input can be either 1 or 0. Multiple 1’s and 0’s can be combined to store more information. For this purpose, multiple input pins will be required. However, this becomes impractical when the input pins required exceed certain number such as 16 or 9 as the microcontrollers do not have this many pins available.The 4×4 matrix keypad solves this problem and reduced the required number of pins to 8 or 6. It is made of a thin and flexible membrane. The 16 keys of the 4 x 4 keypad module are arranged in a matrix of rows and columns. A copper trace connects each of these switches to the others. The rows and column are not connected to each other in normal condition. When we push a key, a column and a row come into contact with each other. In matrix keypads the buttons are divided among rows and columns. Four buttons lie on each row and each column. Thus, columns are connected to external input pins of microcontroller while the rows are connected to output pins of microcontroller. The output pins are high all the time. When a button is pressed the corresponding column goes high and the microcontroller detects it. Finding which column has been activated is easy as each column is connected to a separate pin, however, finding a row is difficult. Once both row and column are identified then the corresponding button can be identified. A clever method to identify the pressed key is to switch off all output pins except one, and then check which input pins is high. Doing this for all the output pins will identify the row. Once the row number is found out, the button can easily be traced out.matrix keypad in STM32STM32 F401 implementationSTM32 F401In CubeMX the relative microcontroller of our choice is selected which in our case is STM32 F401CDU6. The GPIOs that need to be selected as output or external interrupt input are given in the figure above. In the NVIC tab the interrupt should be enabled. Other necessary settings are given below.RCC → Crystal/Ceramic ResonatorSYS → Debug → Serial WireClock Configuration → HCLK → 84 MHzClock Configuration → PLL Source Mux → HSE Once the CubeMX code is generated the following code should be added to the /* USER CODE BEGIN PV */ section./* USER CODE BEGIN PV */ GPIO_InitTypeDef GPIO_InitStructPrivate = {0}; uint32_t previousM = 0; uint32_t currentM = 0; uint8_t key = 0; uint8_t InputData[5] = {0}; int i = 0;/* USER CODE END PV */This code section defines the necessary variables that will come handy later.In the main.c section in /* USER CODE BEGIN 2 */ the output configured pins should be set to 1. /* USER CODE BEGIN 2 */ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1); /* USER CODE END 2 */ While the interrupt callback function void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) should be added to /* USER CODE BEGIN 4 */ section.void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){ currentM = HAL_GetTick(); if (currentM - previousM > 10) { /*Configure GPIO pins : PB6 PB7 PB8 PB9 to GPIO_INPUT*/ GPIO_InitStructPrivate.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9; GPIO_InitStructPrivate.Mode = GPIO_MODE_INPUT; GPIO_InitStructPrivate.Pull = GPIO_NOPULL; GPIO_InitStructPrivate.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStructPrivate); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0); if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)) { key = 68; //ASCII value of D } else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)) { key = 67; //ASCII value of C } else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8)) { key = 66; //ASCII value of B } else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)) { key = 65; //ASCII value of A } HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0); if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)) { key = 35; //ASCII value of # } else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)) { key = 57; //ASCII value of 9 if (i == 4) { //Send Data } else { InputData[i] = 9; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8)) { key = 54; //ASCII value of 6 if (i == 4) { //Send Data } else { InputData[i] = 6; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)) { key = 51; //ASCII value of 3 if (i == 4) { //Send Data } else { InputData[i] = 3; } if(i <= 4) { i = i + 1; } else { i = 0; } } HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0); if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)) { key = 48; //ASCII value of 0 if (i == 4) { //Send Data } else { InputData[i] = 0; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)) { key = 56; //ASCII value of 8 if (i == 4) { //Send Data } else { InputData[i] = 8; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8)) { key = 53; //ASCII value of 5 if (i == 4) { //Send Data } else { InputData[i] = 5; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)) { key = 50; //ASCII value of 2 if (i == 4) { //Send Data } else { InputData[i] = 2; } if(i <= 4) { i = i + 1; } else { i = 0; } } HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1); if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)) { key = 42; //ASCII value of * } else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)) { key = 55; //ASCII value of 7 if (i == 4) { //Send Data } else { InputData[i] = 7; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8)) { key = 52; //ASCII value of 4 if (i == 4) { //Send Data } else { InputData[i] = 4; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)) { key = 49; //ASCII value of 1 if (i == 4) { //Send Data } else { InputData[i] = 1; } if(i <= 4) { i = i + 1; } else { i = 0; } } HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1); /*Configure GPIO pins : PB6 PB7 PB8 PB9 back to EXTI*/ GPIO_InitStructPrivate.Mode = GPIO_MODE_IT_RISING; GPIO_InitStructPrivate.Pull = GPIO_PULLDOWN; HAL_GPIO_Init(GPIOB, &GPIO_InitStructPrivate); previousM = currentM; }} In the callback function the two linescurrentM = HAL_GetTick(); if (currentM - previousM > 10)takes care of the debouncing of the buttons. In keypad it is a common problem that a but hits once is recorded twice or thrice. So, take of that, a little delay is added at the beginning of callback function.The complete code is given below.#include "main.h" /* USER CODE BEGIN PV */ GPIO_InitTypeDef GPIO_InitStructPrivate = {0}; uint32_t previousM = 0; uint32_t currentM = 0; uint8_t key = 0; uint8_t InputData[5] = {0}; int i = 0;/* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/void SystemClock_Config(void);static void MX_GPIO_Init(void);/* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*//* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */int main(void){ /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); /* USER CODE BEGIN 2 */ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */} /* USER CODE BEGIN 4 */void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){ currentM = HAL_GetTick(); if (currentM - previousM > 10) { /*Configure GPIO pins : PB6 PB7 PB8 PB9 to GPIO_INPUT*/ GPIO_InitStructPrivate.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9; GPIO_InitStructPrivate.Mode = GPIO_MODE_INPUT; GPIO_InitStructPrivate.Pull = GPIO_NOPULL; GPIO_InitStructPrivate.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStructPrivate); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0); if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)) { key = 68; //ASCII value of D } else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)) { key = 67; //ASCII value of C } else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8)) { key = 66; //ASCII value of B } else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)) { key = 65; //ASCII value of A } HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0); if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)) { key = 35; //ASCII value of # } else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)) { key = 57; //ASCII value of 9 if (i == 4) { //Send Data } else { InputData[i] = 9; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8)) { key = 54; //ASCII value of 6 if (i == 4) { //Send Data } else { InputData[i] = 6; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)) { key = 51; //ASCII value of 3 if (i == 4) { //Send Data } else { InputData[i] = 3; } if(i <= 4) { i = i + 1; } else { i = 0; } } HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0); if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)) { key = 48; //ASCII value of 0 if (i == 4) { //Send Data } else { InputData[i] = 0; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)) { key = 56; //ASCII value of 8 if (i == 4) { //Send Data } else { InputData[i] = 8; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8)) { key = 53; //ASCII value of 5 if (i == 4) { //Send Data } else { InputData[i] = 5; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)) { key = 50; //ASCII value of 2 if (i == 4) { //Send Data } else { InputData[i] = 2; } if(i <= 4) { i = i + 1; } else { i = 0; } } HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1); if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)) { key = 42; //ASCII value of * } else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)) { key = 55; //ASCII value of 7 if (i == 4) { //Send Data } else { InputData[i] = 7; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8)) { key = 52; //ASCII value of 4 if (i == 4) { //Send Data } else { InputData[i] = 4; } if(i <= 4) { i = i + 1; } else { i = 0; } } else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)) { key = 49; //ASCII value of 1 if (i == 4) { //Send Data } else { InputData[i] = 1; } if(i <= 4) { i = i + 1; } else { i = 0; } } HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1); /*Configure GPIO pins : PB6 PB7 PB8 PB9 back to EXTI*/ GPIO_InitStructPrivate.Mode = GPIO_MODE_IT_RISING; GPIO_InitStructPrivate.Pull = GPIO_PULLDOWN; HAL_GPIO_Init(GPIOB, &GPIO_InitStructPrivate); previousM = currentM; }}
Allen On 2022-10-17
Catalog Introduction How does an LDR work? How to setup ADC in STM32 Introduction The majority of streetlights and outdoor lights are typically operated manually. To manually turn on and off lights is not only risky, but it also wastes energy well as the timing of turning on and off is not optimized. Therefore, an optimized, efficient, and automatic light system is needed to efficiently control light brightness and turn on and off them automatically. In this article, a brief introduction to automatic control of light brightness is given as well as its practical implementation using an STM32 microcontroller and a cheap LDR sensor shown in Figure 1 is demonstrated. Figure 1 LDR breakout board In an automatic light control system, a light detection system is employed that senses the light intensity. If the application requires only to turn on and off a light system, then a threshold value of light intensity is set below which the light will turn on, and above it, the light will turn off. However, if the application is to control the light brightness based on the light intensity in the environment, then a PWM-controlled voltage is provided to the automatic light system. For light detection, a Light Dependent Resistor commonly known as LDR is used. LDR is a sensor whose resistance varies with the intensity of light. This property of an LDR can be used to sense darkness and brightness. Thus, it can be used to automatically control the turn on and off as well as the intensity of the light system. A typical LDR has a maximum resistance value in mega ohms and a minimum resistance value in several kilo ohms. Materials 1STM32 F401/F1032LDR sensor3Potentiometer4LED How does an LDR work? So, how exactly does an LDR operate? LDR works on the principle of photoconductivity. It is an optical phenomenon in which material conductivity increases when light falls upon it. When light or photon strikes the material, the electrons in the semiconductor material's valence band are stimulated to the conduction band. The incident photons must have energy larger than the bandgap of the semiconductor material to cause the electrons to move from the valence band to the conduction band. Hence as light intensity increases more and more electrons are excited to the conduction band which produces a large number of charge carriers. This means that more current will flow in the circuit, and as a result, the resistance will decrease. LDR resistance that changes with the intensity of light cannot be read in a microcontroller. To make it readable in a microcontroller the resistance is represented in terms of voltage. For this purpose, a circuit needs to be designed. Many circuits can be used for LDR. These can be based upon MOSFET, BJET, or an amplifier. However, the most commonly used circuit for LDR to convert its resistance into voltage is the voltage divider circuit. In this circuit, two resistors are installed in series. One side is attached to the positive terminal of the battery while the other is attached to the ground. The schematic of the voltage divider is shown in Figure 2. The output of the voltage divider can be fed to another circuit for other purposes such as a comparator i.e LM393. Usually, a comparator is used in on-off operations where the lights are needed to be turned on and off when a threshold value of light intensity is absorbed by the LDR. A typical circuit for the LM393 comparator is shown below. Figure 2 LM393 comparator usage with LDR The calculation for the voltage divider circuit is pretty easy. Referring to Figure 2, the following equation can be used to measure the output voltage. In this equation, it is assumed that there is no load on the output voltage because that load can affect the output voltage. The output of the circuit is shown in Figure 2 where the change in resistance changes the voltage at the IN1+ pin of the comparator. As we know the voltage changes with the intensity of light. The circuit gives maximum voltage in complete darkness while minimum voltage when placed in bright light. The ADC of the STM32 controller can be used to sense the change in the voltage while the results obtained via ADC can be used to generate PWM. It is the PWM that generates average voltage and hence controls the intensity of light. In this article, both the manual and automatic light intensity control is demonstrated using an LED light. The program and procedure for automatic and manual light brightness control is same, the only difference is that in automatic light brightness control and LDR is used while in manual mode simple potentiometer is used. How to setup ADC in STM32 In STM32, ADC can be configured in three different ways. 1) Polling 2) Interrupt 3) DMA. Polling: In the polling method when ADC conversion starts the CPU operation halts. It is only after the conversion is completed, the CPU resumes working. Interrupt: The second method is by using the interrupt service routine. When ADC conversion competes, it generates an interrupt during which required functions are executed which in our case is to update the PWM value. DMA: The third method is to use direct memory access (DMA). In this method, the ADC directly transfers the data to memory bypassing the CPU altogether. This is the most efficient method of all as it does not involve CPU in the ADC operations and keeps it available for other tasks. In this experiment, we will be using interrupt methods which are both simple and efficient. Required hardware STM32 F401/F103LDR sensor (breakout board will be better)PotentiometerLED Let's build the program step by step Open STM32CubeIDE and start a new projectSelect an MCU which in our case is STM32F401CDGo to SYS -> Debug and select Serial Wire. Select SystTick in TimeBase Source. Go to RCC-> High Speed Clock and select Crystal/Ceramic Resonator. Configure ADC1. Select IN1 and set it to be triggered by software. From the NVIC controller tab check the global interrupt box. Configure Timer 1 in PWM mode with output on CH1. Set the counter period register value to 839 and Prescaler register value to 100. This will ensure 1000 Hz frequency at the output. The following formula can be used to set PWM frequency Setting Prescaler value to 99 while the required frequency is 1000 Hz, the ARR value can be calculated as 839. Finally set the clock frequency to 84 MHz and select HSE as the clock source. And generate the code. The final code is given below #include "main.h"ADC_HandleTypeDef hadc1;TIM_HandleTypeDef htim1;void SystemClock_Config(void);static void MX_GPIO_Init(void);static void MX_ADC1_Init(void);static void MX_TIM1_Init(void);uint16_t AD_Data = 0; uint16_t minimumADC = 1000; uint16_t maximumADC = 3000;int main(void){ HAL_Init() SystemClock_Config(); MX_GPIO_Init(); MX_ADC1_Init(); MX_TIM1_Init(); HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); while (1) { HAL_ADC_Start_IT(&hadc1); TIM1->CCR1 = ((AD_Data-minimumADC)*840)/maximumADC; }}void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc){ AD_Data = HAL_ADC_GetValue(&hadc1);} Figure 3 Duty Cycle in Bright Light Figure 4 Duty Cycle in Low Light Resources Automatics Light.zip
Victoria On 2022-10-06
What is the pcb?What is the pcb assembly?Video about the pcb assemblyWhat are the differences between the PCB and PCBA?Types of pcb assemblySMT assemblyBGA assemblyThrough-hole assemblyMixed assemblyRigid-flex printed circuit board assemblyConclusion of SMT assembly VS BGA assembly VS Through-hole assembly VS Mixed assembly VS Rigid-Flex PCBAFrequently Asked Questions – FAQsWhat is the pcb?The fundamental component of the majority of contemporary electronic gadgets are printed circuit boards, or PCBs. Printed circuit boards are the base on which all other electronic components are assembled, ranging from simple single-layered boards used in your garage door opener to the six-layer board in your smart watch to the 60-layer, extremely high density and high-speed circuit boards used in super computers and servers. The PCB serves as a mounting surface for semiconductors, connections, resistors, diodes, capacitors, and radio equipment, all of which "speak" to one another.PCBs are the best choice for these applications because of their mechanical and electrical qualities. Roughly 90% of the PCBs produced today are rigid, making them the most common type of PCB in the world. Some PCBs are flexible, allowing the circuits to be stretched and folded into shape. Other times, flexible circuits are employed in applications where they can withstand hundreds of thousands of bend cycles without failing. Ten percent or so of the market is made up of these flexible PCBs. A tiny subset of these kinds of circuits are referred to as rigid flex circuits, which have firm parts of the board that are perfect for mounting and connecting components and flexible parts that offer the benefits of flexible circuits that were previously mentioned.What is pcb What is the pcb assembly?PCBA = assembly of PCB. A surface encapsulation procedure is used to integrate various electrical components on the circuit board. The box assembly comes next, which joins the finished product's outer case and assembled PCB. In other words, the PCB bare board travels via the SMT top section before traveling through the full DIP plug-in process, also known as PCBA. In contrast to PCB'A, which adds a slant point, which is the norm in Europe and America, this approach is widely employed in the nation. PCBA stands for printed circuit board assembly. If a market is viable, mass production for new electronic designs would typically follow prototype pcb assembly (Sample PCBA) to verify designs.PCB Assembly Video about the pcb assemblyVideo Description: This is a great explanation of the printed circuit board (PCB) and electronics manufacturing process in the context of IOT. What are the differences between the PCB and PCBA?The terms "bare circuit board" (PCB) and "circuit board plug-in assembly" (PCBA) both relate to the SMT technique. A finished board is one, and a naked board is the other. According to the number of signal layers, PCB (Printed Circuit Board), made of epoxy glass resin material, is divided into 4, 6, and 8 layers. The most typical layer counts are 4 and 6. The bare board has chip components like chips attached to it. PCBA can be thought of as a finished circuit board, and it can only be produced if the circuit board's manufacturing process is concluded. PCBA=Printed Circuit Board +Assembly. Types of pcb assemblySMT assemblyBGA assemblyThrough-hole assemblyMixed assemblyRigid-Flex PCBA SMT assemblyWhat is the SMT assembly?SMT, or surface mount technology, is its full name. SMT is a technique for attaching parts or components to circuit boards. SMT has replaced other methods in PCB assembly due to its superior results and increased efficiency. Through-hole assembly was mostly utilized in the past by PCB producers to add components. But SMT has introduced welding technology to replace the previous assembling technique. And all electronic businesses, including those in computers, telephones, smartphones, home appliances, etc., use PCBs made using the SMT assembly process. Printing solder paste, mounting components, reflow soldering, AOI, or AXI are all components of the basic SMT assembly process.SMT Assembly The advantages of SMT assemblySmall size and lightweightThe total size and weight of the PCBs are reduced by directly attaching the components to the board using SMT technology. This assembly process enables us to fit more components into a small area, resulting in smaller designs and improved performance. High reliabilityAfter the prototype has been validated, the entire SMT assembly process is almost fully automated using precise equipment, which reduces the possibility of human error. SMT technology ensures the consistency and dependability of the PCBs because of automation. Cost-savingSMT assembly is often carried out using automated equipment. Even though the machines' input costs are expensive, the automatic machines assist in reducing manual steps throughout SMT operations, which considerably increases production efficiency and, over time, lowers labor costs. Additionally, through-hole assembly requires less materials, which lowers the cost. SMT assembly capabilities of PCBGOGOA fully automated SMT workshop for bulk production is owned by PCBGOGO. We also offer manual welding services for difficult items, prototyping, and small quantity orders. For PCB assembly, we have FR4 board, aluminum board, flexible board, and rigid-flex board options. Other assembly types, besides SMT assembly, include BGA assembly, through-hole assembly, mixed assembly, and kit assembly. The following files should be included with your SMT orders: a Gerber file (used for PCB fabrication), a BOM list, a CPL list, or a PNP list (pick and place). BGA assemblyWhat is BGA?An integrated circuit is packaged using a surface-mount device called a ball grid array (BGA), sometimes known as a chip carrier. Devices like microprocessors are permanently mounted using BGA packaging. A BGA can offer more connector pins than a dual in-line or flat package can accommodate. Instead of simply the edge, the entire bottom surface of the gadget can be used. Additionally, compared to a perimeter-only type, the traces connecting the package's leads to the wires or balls that connect the die to the package are typically shorter, improving performance at high speeds.BGA Assembly The advantages of BGA assemblyHigher-density circuitsThrough-hole circuits got more densely populated, making it practically impossible to solder them precisely without crossover or short-circuits. Heat conductionBGA circuits minimize overheating issues by facilitating significantly easier heat transfer from the integrated circuit externally. Lower inductanceThe likelihood of interference issues in a BGA circuit is considerably reduced because each solder ball typically only measures a few millimeters in size. Through-hole assemblyWhat is a through-hole assembly?Electronic circuits are created using the through-hole assembly technique, in which the components are inserted using leads. It describes the installation procedure in which the leads are inserted into the pre-drilled holes and the components are soldered to the board using either wave soldering or manual soldering.PCB design evolved over time from single-sided to double-sided, and finally to multi-layer boards. It is challenging to adapt through-hole assembly to the needs of contemporary electronics. In today's PCB production, SMT technology has essentially taken the place of through-hole construction. However, some applications, including those for electrolytic capacitors, connections, and big transformers, still require through-hole installation.Through-hole AssemblyThe advantages and disadvantages of Through-hole assemblyHigh reliabilityAs opposed to SMT components, which are simply soldered on the PCB's surface, through-hole assemblies require leads that are inserted into the holes to secure the components to the board, which results in higher environmental stress. As a result, through-hole assembly provides a stronger physical connection, making it the preferred method for the aerospace sector and the military, both of which have high dependability requirements. Easy for manual operationBecause replacing or moving through-hole components is simpler, this assembly technique is frequently utilized in applications that call for PCB testing and PCB prototyping. Higher durabilityIndustrial machinery and equipment frequently use through-hole components due to their strong heat resistance and high stress tolerance. Through-hole LEDs are used in the LED lights on enormous billboards because they are strong and bright. Lower manufacturing efficiencyDue to the extra step of drilling and hold the components using leads, through-hole assembly is time-consuming, which causes higher costs and lower production efficiency. Limited PCB designDrilled holes must penetrate all layers of the board in through-hole assembly, which makes multi-layer PCBs unsuitable since it makes layout design and PCB manufacturing more challenging. Additionally, the board would be larger overall than SMT PCBs, which would limit its range of applications. Mixed assemblyWhat is the mixed assembly?Although surface mount technology has taken over as the primary mounting technique in PCB manufacture, some components are still incompatible with SMT assembly. The same board must then be used for SMT assembly and THT assembly. A mixed assembly is what is referred to as a blend of assembly technologies without the usage of solder paste during production.The majority of the components are welded in surface mount configuration on the board, although mixed PCB assembly is required for some specific components that are not available in the SMT process.Mixed AssemblyThe advantages of Mixed assemblyThrough-Hole, SMT, and BGA components are housed on the PCB in a mixed assembly.SMT (Surface Mount Technology) or single- or double-sided mixed technology for PCB assembly BGAs have one or two sides, as well as micro-BGA.100% X-ray inspection during installation and rework.Small-quantity PCB board components include all varieties of BGAs, QFNs, CSPs, 0201, 01005, POP, and Pressfit Components.SMT and through-hole polarized capacitors are examples of part polarity capacitors.Rework capabilities include the ability to remove and replace BGAs and MBGAs, as well as having experience with ceramic and plastic BGAs. Rigid-flex printed circuit board assemblyWhat is Rigid-Flex PCBA?Printed circuit boards that combine rigid and flexible board technologies are known as rigid-flex boards. Depending on the application's design, the majority of rigid flex boards are made up of many layers of flexible circuit substrates that are outwardly or internally attached to one or more rigid boards. The flexible substrates are typically formed into the flexed curve during manufacturing or installation and are intended to be in a constant state of flexibility.Rigid-Flex PCBAThe advantages of Rigid-Flex PCBABy using 3D, space requirements can be reduced.The size of the board and the weight of the entire system can be decreased by doing away with the requirement for connectors and cables between the various rigid pieces.There is frequently a lower part count when space is maximized.Lower solder junctions guarantee more reliable connections.Assembling rigid boards is easier than handling flexible boards.PCB assembly procedures that are simpler.Simple modular interfaces to the system environment are provided by integrated ZIF contacts.Simpler test conditions are used. a thorough test is conducted before installation is possible.Rigid-Flex boards greatly lower the cost of logistics and assembly.It is feasible to make mechanical designs more sophisticated, which raises the degree of freedom for ideal housing solutions. Conclusion of SMT assembly VS BGA assembly VS Through-hole assembly VS Mixed assembly VS Rigid-Flex PCBA Which one is better in PCBA: SMT, BGA, or Through-hole?Through-hole technology might be the most effective for low-volume PCB fabrication (like prototyping). For components that must withstand high stress, through-hole is frequently viewed as the superior option since wire leads provide a solid link. The preferred mounting method for front connectors, where USB cables and cords will be plugged in, is frequently via hole. However, drilling holes costs more and requires soldering on both sides of the PCB, which extends the production cycle. On multi-layer boards, through hole connectors can reduce the available routing space.Multiple advanced functions, effective performance, and enhanced speed are required for modern electronic gadgets, all in a smaller device. Even with more electronic components, the assembly still needs to be thinner. BGA packages are the best choice for these needs. For instance, BGAs are typically used in the manufacturing of ICs having more than 200 I/O connections. Surface Mount is a superior option when production volumes are high since SMD components take up less space, resulting in a more compact, component-dense circuit board. SMT is a more dependable method than manual assembly using through-hole technology because SMDs are amenable to automation utilizing pick-and-place robotic machines—no drilling is necessary. The industry standard method for back connectors is SMT. SMT does have some drawbacks, too. For example, it is not recommended for connecting high-stress components, and it necessitates an initial investment in pricey technology for mass production.Overall, SMT is more cost-effective and time-efficient. The comparison between SMT assembly and THT assemblyFirst, SMT components are fully automated and welded onto the board using a reflow machine. While wave-soldered and hand-soldered techniques are both traditional approaches in the THT assembly process, THT assembly requires pre-drilling holes in the board and employing leads to link the components and circuits.Second, only wave soldering is permitted for PCBs with through-hole components; reflow or wave soldering are not permitted for PCBs with surface mount devices (SMDs). Therefore, if both SMT components and THT components are used on the board, there are extra stages in the assembly process. Typically, SMT is carried out first, followed by THT assembly.Thirdly, SMT assembly can be completed quickly and accurately thanks to advanced and precise machinery. SMT is more suited to high-density and tiny size PCB applications due to its ability to precisely insert thin and small components on the board. Additionally, THT is favoured by components with high requirements for dependability and huge size since it offers more durable connections than SMT components.SMT assemblies have a number of advantages, including high productivity, high precision, light weight, and low cost. SMT is quicker and more cost-effective for mass production. THT assemblies are often very dependable, have a high stress tolerance, are heavier, and cost more. THT is the ideal assembly technique for prototype and small-scale PCB production. The comparison between SMT assembly and Rigid-Flex PCBAElectrical components are put directly onto the surface of a printed circuit board using surface-mount technology (SMT) (PCB). Because SMT components can have smaller leads or no leads at all, they are often smaller than their through-hole counterparts.Photolithographic technology is used to create flexible printed circuits (FPC). Stiff flex printed circuit boards are circuit boards that combine rigid and flexible board technology. Depending on the application's design, the majority of rigid flex boards are made up of many layers of flexible circuit substrates that are outwardly or internally attached to one or more rigid boards.All in all, SMT is more cost-effective and time-efficient and Rigid-Flex PCBA is time-consuming and expansive. Frequently Asked Questions – FAQsWhat is PCB board?Copper conductors are used to make electrical connections between components on a printed circuit board (PCB), which is an electronic assembly. Electronic components are mechanically supported by printed circuit boards, allowing a device to be housed in an enclosure. What are the differences between the rigid pcb and flexible pcb?From their names, it may be deduced that stiff PCBs and flex PCBs differ most significantly. Flex PCBs can be bent or otherwise shaped to fit inside the designated system while rigid PCBs cannot be bent or otherwise shaped. When properly engineered, flexible circuits can be repeatedly stretched for hundreds of thousands of cycles without breaking. Flex boards are more expensive on average, but they are necessary for applications with constrained space requirements, such as consumer electronics, medical devices, space applications, and automotive applications. The affordability of rigid circuit boards is a major factor in their popularity. Because rigid circuit boards take up less space, manufacturers can save a lot on traditional electronics, especially consumer electronics. What does PCB assembly mean?A printed wiring board (PWB), on the other hand, is a board that is devoid of components and is used in electronics that do not require complicated functionality. A printed circuit board (PCB) is a completely constructed board that has all the circuitry required to go into an electronic device. What is PCB SMT assembly?The technique of soldering electronic components to a printed circuit board (PCB) is known as SMT assembly technology. Small amounts of molten solder paste are utilized in this procedure to join the component leads to pads on the PCB surface. What is PCB BGA assembly?Ball grid array, sometimes known as BGA, is a type of packaging used to mount components with hundreds of pins, such as microprocessors. It also goes by the name Ball Grid Array. BGA assembly is the process of directly mounting the BGA packages or integrated circuits (ICs) onto the BGA board and soldering them in place.
kynix On 2022-08-31
Join our mailing list!
Be the first to know about new products, special offers, and more.
Feature Posts
How Resistors Work: From Basic Principles to Advanced Applications2025-07-30
DC Switching Regulators: Principles, Selection, and Applications2025-05-30
FPGA vs CPLD: In-depth Analysis of Architecture, Performance and Application2025-05-07
MOSFET Technology: Essential Guide to Working Principles & Applications2025-05-04
SMD Resistor: Types, Applications, and Selection Guide2025-04-30