FOC Driver + Feedback Magnetic Sensor - Arduino

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
not actually FOC where is the feedback posted anyway guys that was an FOC control but the encoder got burned remember so I could only use it in open loop circuit and now I have a new PCB and this time as you can see I've made it with two sensors one that is expensive and a cheap one and surprise to surprise the cheap one is actually better than the expensive one I mean it's not better but I got better results with it so guys this is my journey of creating one of those Hub motor that the Baston Dynamics robot have so for that you need torque speed but also Precision on one hand the brushless motor has the torque and the speed and on the other hand the stepper motors have the Precision with the step controlling and all that but what if I told you that you can control the brushless motor with a lot of torque but also a lot of precision and we do that using FOC so if you also want to make your own robot dock you need to see this and learn about FOC so let me show you everything about this project the Circuit of the PCB the sensors and the components that I'm using how to implement the code what is actually FOC and how to do that with the feedback and everything about this project but this time with a closed loop system that being said let's get [Music] [Music] started what's up my friends welcome back this new project is awesome now the PCB kind of looks the same as the previous one but it has some changes I've ordered it purple from PCB way and this time it has two sensors and I've made it so you could just snap the sensor PCB with your hand without having to cut it so if you want to try this awesome project get my Gerber files from below and then go to pcb.com and here is very easy to order just for $5 click the code now button and on the next page add the size of the PCB the amount and also select a color this time I've selected the purple one add it to the card and on the next page upload the Gerber files and place the order that's how easy is to use the services of PCB wave for PCB prototyping and as always I received the pcbs in just a few days and they look awesome I think that for this project I like better the purple color than the red one from the previous version so now we have the pcbs to get the sensor smaller PCB just snap them with your hand like this so now we have three pcbs at the same price of just one I could order them separately but like this we save some even more money the small pcbs are for the encoder sensor one is for the as 5600 sensor which only cost like $2 and the other one is for the as 5048 sensor which cost around $14 on the main PCB as you can see we have a place for the smaller PCB with a pins for pwm and also I Square C and that's because these sensors could output both pwm and also I Square C values for the angle these IC are working with radial magnets meaning that the South and the north are radial positioned and we use this to know the exact angle of the motor shaft on the main PCB we have the atga 328 chip for the main microcontroller and the L 6234 PD for the motor driver and the PCB has some extra stuff such as the buzzer for sound notifications a mosfet and a fan output to cool down the components and two inputs for a potentiometer and an ice Cy control the PCB also has some screw holes to go exactly on top of these motors and these are brushless triple face Motors and we need them to have as many stator coils as possible you see this motor from a drone has few Stater coils so it could spin very fast but the position control at low speeds would be awful so for slower and smooth movement in FOC we need more Stater coils so the sign signal could pass smoothly that's why for example the hoverboard motor from a previous video has so many Stater coils and the motor spins very smoothly slow but smoothly by the way usually brushless motors are labeled something like this let's say 12n and 14p meaning 12 Stater electromagnets and 14 permanent magnets just so you know actually on a brushless motor you could have something like this 222 Q for the diameter and the height let's say 850 KV for the revolution per volt and 12n 14p for the magnet configuration the more you know huh anyway the motor I'm using has 22 magnets and that's important for later in the code on the shaft we have to glue one of those radial magnets so you can see how the magnet is now rotating at the same time with the motor then the PCB gets on top of it with the sensor and that's how we can know the position at any moment look for example here we have the pwm output from the sensor while rotating the shaft as you can see it gets bigger or smaller according to the angle of rotation and we can easily read this pwm signal in the uino code that being said let's assemble the PCB I take the main microcontroller out of an Arduino nanoc clone in order to be sure that it has a boot loader because you see I've also bought some atega 320 chips like this but these are blank chips without a boot loader I could burn the boot loader but we need access to the ISP pins which this PCB doesn't have and I place the ISP pads on pretty much all my pcbs as you can see on these boards we have the MOSI and the Miso pins but now when I need them most I forget to add the pins I'm such a genius anyway the first thing that I've sold her was the at Mega chip the resonator the reset pullup and the DTR capacitor and the values are on the schematic then I test it using one of those ftdi programmers upload any code to it and if it works then the chip part is good to go but you see the nanoc Clone that I took the chip out was using a 168 microcontroller instead of the 328p microcontroller and I haven't seen that they are basically the same but the 61 has less memory and the code that I've prepared for it won't fit so I had to take the chip out once again and solder another one again I'm such a genius now that the chip works I solder the rest starting with the driver chip and this could handle up to 4 amps and it will get quite hot trust me that's why the PCB also has some pads for a cooling fan but we won't need it for the tests solar the small resistors and capacitors also some diodes the LED and that's it then on the small PCB I desolder the magnetic encoder from a module and then I soldar it to my PCB then I add the encoder PCB on top of the main PCB the motor gets holder to these three pads for the face a b and c and the board will get on the back of the motor using screws face to face with the magnet that we have glued before to the shaft using some super glue now the the setup is ready for the code the PCB has U pads for the fddi programmer so connect it and then we add the USB cable and let's start with some tests I have two boards one with the as5600 sensor and the other one with the as- 5048 now even if the as 5048 is a lot more expensive for some reason I was only able to make it work with pwm mode and pwm mode is not as precise as I Square C that's why I've decided to continue with the 5600 so for the first test I download the AMS 5600 library and I around the r angle code upload the code and open the monitor as you can see I can now see the angle when rotating the motor so the sensor is working for the next part we have to remember the open loop control first and if you remember this was the code and I was using SP signals using this lookup table I was using the same approach as for my sinos soidal inverter project using spwm now this is how you can get these values I had two options I could calculate them in the Arduino code or using a lookup table so I've decided to calculate the values directly in the code but if you want to use a lookup table here's how you can get the values let's say that you want 128 points for the lookup table so in AEL I make 180° from 0 to 180 like this in the next column I calculate the sign value use radians function because Excel is working in radians and not in degrees then I multiply the result by the maximum value of the Arduino PM signals of 8 Bits which is 255 and that's how I get my values 0 6 13 19 and so on till 255 and then decreasing down to zero and this represents a sign Loop of 180° the other side is the same but applied to the other phase of the motor but in the new code I calculate the spwm signals for each phase with 120° phase difference and then I constain the values to range of 0 to 260° to get the pwm values I was using the sign function and then apply the PM signals to the driver with a fixed torque value but uploading this code would only rotate the motor without the feedback as we have seen in the previous tutorial I can change the angle with a potentiometer but if I move it with my hand it won't go back to the original position because this is not a closed loop but now we have the sensor so now let's check the closed loop code with the p control that I've made first we read the potentiometer for the set point then we get the real angle from the magnetic sensor then we divide the angle for the electrical angle because you see it's important to know the amount of pole pairs that our motor has as I've told you my motor has 22 magnets so it has a total of 11 pole pairs so in order to make a full real rotation we are making 11 electrical rotation inside of the coils that's why here in the code we map the real shaft position according to the electrical rotations then we calculate the PID error depending on this error we first decide if we will rotate clockwise or counterclockwise then we make the P code which is actually PD code I haven't used the I variable the P value is proportional so just the error multiply by the P constant the D value needs the elapse time and the error difference and finally we sum up the pad output as the pad torque variable I've placed the pwm signals in a separate function and here depending on the position we calculate the spwm signals using again the sign function then apply the values to the output pins and that's it I upload this code and let's check it out look I can change the angle with the potentiometer but now if I rotate it with my hand it will get back to the same position now that's real FOC control with a good feedback and since we have the P code the movement is quite responsive you can change the p and the D constants in the code if you want and try different values for more speed or Precision it has quite some torque and I'm only running it at 7 volts because at more power the driver will get quite hot you could even rotate this a lot and it will still get back to the original position that's quite awesome to see by the way this is also compatible with the simple FOC Library so you could download that from GitHub and test it out it has some nice features for example my motor could only go from 0 to 360° because for now the code is not made to make more than one rotation when I get to Z or 360 the motor starts spinning as you can see here because the error is always greater or smaller than zero I will improve my code for future updates so now you could use my setup for your own FOC project for making a robot a balance or any other P control system using brushless motors you've also learn how the pulse of the motor affect the code and how the feedback is implemented with the magnetic sensor you have all my files below the code the schematic the PCB files and everything that you need on electron.js with your results thanks again and see you later guys hey guys so that was another project and I hope that you like it as you all know to buy all these modules a huge help from you is from patreon so if you want to support me you can support me there but also just commenting below giving me a like or sharing this video it will also support my channel so thank you very much to all my patrons and to you guys
Info
Channel: Electronoobs
Views: 30,242
Rating: undefined out of 5
Keywords: FOC, field oriented control, driver, brushless, Arduino, homemade, PCB, robot, harmonic, drive, gear, sinusoidal, SPWM, feedback, AS5600, encoder, magnetic
Id: pzGRKyHlXsM
Channel Id: undefined
Length: 14min 34sec (874 seconds)
Published: Sun May 26 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.