📜 ⬆️ ⬇️

Device and operation of input / output ports of AVR microcontrollers. Part 3

Connecting the transistor to the I / O port line

After reviewing this material, in which everything is described in great detail and in detail with many examples, you can easily master and program the input / output ports of AVR microcontrollers.


An example will be considered on an ATMega8 microcontroller.
')
We will write the program in Atmel Studio 6.0 .

We will emulate the circuit in Proteus 7 Professional .

The maximum current that each input / output port is able to pass is 40 mA.
The maximum current that each line of the I / O port is capable of passing is 20 mA.
Before connecting the load, including the transistor to the lines of the I / O port, you can burn it by exceeding the permissible load on the line of the I / O port.
To limit the current that flows through the lines of the I / O port of the microcontroller, it is necessary to calculate and connect the current-limiting resistor.



Figure: Rapinovka npn-type transistor.



Figure: Rupinovka pnp-type transistor.



Figure: Connection to the npn-type transistor microcontroller.



Figure: Connection to a pnp-type transistor microcontroller.

The resistance of the current-limiting resistor connected to the lines of input / output ports when a transistor is connected is calculated by the formula:



Example:
- switching on a powerful LED through a transistor switch.



Figure: Connection to the microcontroller of the LED through an npn-type transistor switch.

LED data:
- power supply voltage - 5V ;
- direct voltage drop on the LED - 1.35V (It is taken from the datasheet to the LED );
- direct current on the LED - 120mA (It is taken from the datasheet to the LED );
- Reliability factor LED robots - 75% ( Taken from the datasheet to the LED );

Data on the transistor BC547 take from Datasheet-BC547:



Data on the microcontroller:
- power supply voltage - 5V ;
- voltage drop on the I / O port line - 0.5 V ( Taken from the datasheet to the microcontroller: Vol (output low voltage) - if the current flows in, and Voh (output high voltage) - if the current flows out );

Calculate the resistance R1 :



Thus, the value of the resistor R1 = 38.33 Om, the nearest larger resistance value is selected, for example, 39 Ohms.

After determining the value of the resistor R1, it is necessary to calculate the power P1, measured in watts, which will be released in the resistor, as heat when current flows in the circuit.



Having calculated the allocated power at the resistor, we choose the nearest larger value of the resistor power.

Calculate the resistance R2:



Thus, the nominal value of the resistor R2 = 4750 Om, the nearest lower resistance value is selected, for example, 4.7 kΩ.

Having determined the value of the resistor R2, it is necessary to calculate the power P2, measured in watts, which will be released in the resistor, as heat when current flows in the circuit.



Having calculated the allocated power at the resistor, we choose the nearest larger value of the resistor power.


- connect npn-type transistor to the I / O port line:



//    #include <AVR/io.h> #include <stdint.h> //   int main(void) { //   / DDRC = 0b11111111; //    C   "" PORTC = 0b11111111; //    C  .«1» (     Vcc) //   while (1) { } } 


- connect the pnp-type transistor to the I / O port line:



 //    #include <AVR/io.h> #include <stdint.h> //   int main(void) { //   / DDRC = 0b11111111; //    C   "" PORTC = 0b00000000; //    C  .«0» (     GND) //   while (1) { } } 

Source: https://habr.com/ru/post/255715/


All Articles