⬆️ ⬇️

Making an "eternal" mass air flow sensor on the ATiny13





This project appeared because of the reluctance to buy a used part for about 30 (thirty) years of detail for a very big amount of 3000 - 5000 rubles. We can say that it will be a sample of the pen in the circuit design and programming of microcontrollers. If interested - continued under the cut.



Caution many photos!



So, we start to prop the bikes with crutches.

')

Input data



BMW E30 in the back of 1986 with the engine M10B18 (4 cylinder, 1.8l, injector):







Problems


1. sneezes

2. Does not go

3. Eats and does not get fat



Years in Russia did not spare her. High-quality gasoline, salt baths, "porous roads . " However, most of all she got from the former owners and the harsh Russian auto mechanics, senseless and merciless, who made repairs of dubious necessity and efficiency. A striking example of one of these repairs, you can admire the KDPV. And what is this little white there, all in solder? This is a ceramic board - the main part of the DMRV , film resistors are applied to it and the path along which the moving contact should run. As you can see in the photo, she cracked, and someone tried to restore it by such a barbaric method. Unsuccessfully. Here it is - the root of all problems! Here it must be said that DFID is the main sensor affecting the mixture formation.



Some theory



Our machine is equipped with the miracle of the German industry with the L-Jetronic distributed injection system.



Google says:

The system of distributed injection L-Jetronic is a system of pulse injection with electronic control of the quantitative and qualitative composition of the fuel-air mixture. To ensure the pulse injection of fuel in the system used nozzles with electromagnetic control.










Well, distributed - it is loudly said, here all 4 injectors are connected in parallel and, accordingly, pshikayut at the same time, although yes, I find fault with it, they are installed opposite each other to its cylinder in different places of the intake manifold - i.e. distributed. The brain here is rather silly - idling, ignition, does not control the heating rotations.



All that is subject to him is a few sensors and injectors.



Let's return to DFID. Here is installed electro-mechanical DMRV, popularly referred to as "shovel", apparently for the characteristic form of a movable damper.







Its principle of operation is quite simple: the air consumed by the motor passes through the inlet, and, depending on the intensity (count the air mass per unit of time), deflects the measuring flap by a certain angle. A movable contact is installed on the gate axis, which runs along the path of our long-suffering card from the first picture.



Solutions to the problem:



1. Buy a new DFID - cosmic money costs 35,000-60000 rubles, comparable to the cost of a car.

2. Buy BU DFID - 30 years of operation, no guarantees, it costs 3000 - 5000 rubles.

3. Buy a new board (unoriginal, do in small batches) - the price is 300r + forward, it looks like this:







As you can see, the design is different from the factory. Reliability is questionable, on the Internet you can find negative reviews about the allegedly fragility of this decision, confirmed by photos of worn-out boards of this type.



4. Buy a modern type DFID without moving parts + a so-called converter - the price of the issue is a little scary, just need to adapt the intake tract, increase the length of the pipes, etc.



5. Come up with something different .



For me, the choice was obvious.



I decided to leave the mechanical part, as I did not find any signs of wear. I think it will last longer than the rest of the car.



The task has simplified a bit, it is necessary to convert the angle of rotation into voltage. But no, wait, not everything is so simple ... The fact is that, as I already said, the brain is quite silly here and, accordingly, he wants to receive the most up-to-date data at the entrance. This is reflected in the DFID design - the graph of output voltage versus the angle of rotation of the flap axis is nonlinear, and the added complexity is scaled by the resistance of the air temperature sensor, which is also integrated into the DFID. Accordingly, the sensor characteristic should change depending on the air temperature.



The search for a ready-made circuit solution did not lead to success. The problem with the wear and tear of DFID of this type has touched many, many topics in specialized forums where people discuss dozens of pages how to solve it.



For a start, I would like to receive data on the angle of rotation of the axis. Variable resistors and other mechanics I immediately dropped as unreliable. The optical sensor is good, but dust can cause trouble, and there is enough dust on the road. Magnetic sensors are probably what you need.



I found this: KMA-200 .







On the move, I could not buy it in my own wilderness. And accidentally stumbled upon such a ready-made TPS in which KMA-200 was applied.







In the load I get a magnet with a mount, the sensor is already on the board with the necessary strapping, coated with varnish that protects against moisture and static. Found by the way a similar project .



Fine!



At the output of this sensor voltage from 0 to 5 volts, the dependence on the angle of rotation is linear. We need to somehow convert it to the characteristic we need. Analog circuits could, in principle, provide this, but they would be rather complicated in design and adjustment, for example, some integrator on thermal operators with thermal compensation, but this is difficult for me ...



Then I remembered that I have a handful of ATiny13, why not use them?



Sketched and modeled shemku:







A little about the scheme.





Then a simple filter and an LM358 operational amplifier from the old motherboard (CG = 1 + (330000/100000) = 4.3), which controls the field engineer (from the same motherboard). Maximum output voltage = 4.3 * 2.5 = 10.75V.



Why do you ask a fieldman? And who knows, I will answer you! Excess will not be. Using this scheme, I managed a powerful load in the form of several automotive lamps connected in parallel just to check that it could also.



In general, all the details I had in stock except for the rotation sensor.



Time to write the firmware! This is my first MK firmware, so of course everything is not optimal, and of course I chose the slightly weird BascomAVR tool, in which I have to write in some kind of pseudo-Cubesian. Obviously, the compiler built in there is not very optimized, the firmware turns out to be bold, and the polynomial interpolation I wanted to cram in there unfortunately did not fit. I had to implement the approximation in three straight lines. Why three? Because it is no longer climbed (Bascom + 1 kb flash).



$regfile = "attiny13.dat" $hwstack = 8 $swstack = 16 $framesize = 16 Config Portb.1 = Output Config Timer0 = Pwm , Prescale = 1 , Compare B Pwm = Clear Up Config Adc = Single , Prescaler = Auto Start Timer0 Dim Adcval As Word , Temp As Single Do Adcval = Getadc(2) '  Select Case Adcval '        Case 0 To 306 Temp = Adcval * 2.2 Adcval = Temp Case 307 To 613 Temp = Adcval * 0.9377 Adcval = Temp Adcval = Adcval + 384 Case 614 To 1023 Temp = Adcval * 0.15 Adcval = Temp Adcval = Adcval + 870 End Select Temp = Adcval * 0.0009765625 '   Adcval = Getadc(3) '  Temp = Temp * Adcval '        Pwm0b = Temp * 0.25 '   Loop End $prog &HFF , &H7A , &HFF , &H00 ' generated. Take care that the chip supports all fuse bytes. $prog &HFF , &H6A , &HFF , &H00 ' generated. Take care that the chip supports all fuse bytes. $prog &HFF , &H7A , &HFF , &H00 ' generated. Take care that the chip supports all fuse bytes. $prog &H00 , &H00 , &H00 , &H00 ' generated. Take care that the chip supports all fuse bytes. $prog &H00 , &H00 , &H00 , &H00 ' generated. Take care that the chip supports all fuse bytes. 


To find out the equations of lines literally for 10 minutes, I sketched a dull soft in Qt Creator, I moved the control points, I decided on the position of the lines.







The red line is the desired characteristic, the blue line is an approximation of straight lines. Next, compile and upload the firmware to the emulator. Everything moves as I expected.



In a hurry, we part the board and uncover the laser iron.







We poison, we solder, we fix the jambs of the wiring (well, where can we go without them).











Attentive reader and experienced amateur radio will notice 2 errors that I made when sealing.



Further inclusion, check of basic parameters, and daily running in the different modes. The audit showed that everything works as planned. The time of assembly and installation on the car.















After tuning by the trimmer, the car starts to work as it should, later the gas mileage and dynamics were checked, everything turned out to be normal, those corresponded to the declared characteristics. The machine rolled to the south from central Russia, no problems appeared.






I believe that the first experience of programming microcontrollers, and in principle and the creation of circuits, was successful for me. Of course there are flaws: for example, the choice of programming environment. In the next project I already used CVAVR, the firmware is much more compact. The choice of a microcontroller could also be called not successful, although I did not choose it, I had one, and there was a desire to use it. Immediately after completing this project, I ordered several ATiny85s, which have 8 times more memory, but while the package was being sent, they suddenly bought this car, and the DFID remained with a non-ideal algorithm).

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



All Articles