The project aimed to create an electronic speed controller (ESC) for a DC motor using a PIC microcontroller. Initially, the current shunts revealed a normal-looking behavior but showed sporadic current flow that didn't get interrupted even when the external interrupt pin was pulled high.
To address this issue, an additional timer was used as a reference value to measure the time it took for the current to reach a previously utilized threshold value of around eight microseconds. The second timer was then set up to interrupt at a value of 16 (also around eight microseconds) and its output was connected to the corresponding interrupt instead of measuring.
After uploading the new code, some decent results were achieved with only minor current spikes. The motor rotated well enough that a propeller could be added, creating a light breeze. However, when trying to reach higher rotation speeds, the rotor got stuck due to increased current flow through the 16-2-3-4 driver.
The reason for this unwanted behavior was attributed to the lack of feedback from Hall effect sensors, which would have provided information on the position of the rotor. To overcome this limitation, a technique called BEMF (back electromotive force) was used instead.
In this method, the coils A and C were powered according to step one, while coil B floated in the air due to magnetic fields generated by the motor's magnets. As one magnet moved towards coil B, it induced a positive voltage into it. The perfect moment to switch to the next step would be when the magnet just about to pass phase B, which coincidentally was also the point where the magnet started inducing a negative voltage into the coil.
Using this zero-crossing point as an indicator to move to the next step, a second comparator C was added and connected to the inverting input of the three PIC16F877A comparator stages through the virtual neutral point of the DC motor. Each phase was then connected separately to each one of the comparator's non-inverting inputs.
The outputs from these comparators were connected to pins 10, 11, and 12, creating a PWM signal that changed its output state whenever a zero crossing occurred. A pin change interrupt was set up on pins 10, 11, and 12 to optimize the current flow by increasing the on-time for the current step and also prematurely increasing the step counter.
After uploading the code one last time, it was observed that the motor still worked well at low speeds but could not reach rotation speeds fast enough to create a sufficient uplift due to increased current flow through the driver. This issue would be addressed in future projects by using more modern ICs in combination with beefier MOSFETs to create a more powerful ESC.
The project aimed to provide an affordable and efficient solution for creating an electronic speed controller for a DC motor using a PIC microcontroller, but further improvements are necessary to reach commercial-grade performance.
WEBVTTKind: captionsLanguage: enwe ended the first part of this project with all Bill DC motor desperately trying to move for which the reason was that they current rise to it and the incapability of my power supply it to cover that demands to find a suitable solution now we already came to the conclusion that current chopping would be the way to go which was also confirmed if we have a look at the current curves while utilizing the commercial ESC to implement this feature the datasheet of the l6 2 3 4 presents us an application guides as soon as the current reaches the threshold value we simply deactivate the high side MOSFETs and activate the corresponding low side bottom so that the 2 coils are shorted to one another and thus decrease the current flow after said wait time the low side one then turns off the high side one reactivates empty current Rises through the coils once again until the process repeats so to start off the integration of this current chopping technique into the arduino codes i added six additional step functions which are pretty much identical to the counterparts except that instead of connecting one phase to the supply voltage they connect all phases to ground now to set a threshold value in which those intermediate steps are activated we can either measure the current through the motor or simply use an additional timer but since i already added current channels to the circuits to which the current of each phase will flow i will firstly try to measure the current eddy current flow of around 1 amp we get a voltage drop of roughly 0.2 volts across two resistors which once the voltage is measured by the analog pin a 6 equals value of 41 this will be a threshold value for the chopping and to activate it every move to do 1 flag for now and replaced it with a white flag in combination with an analog weed function before each step commands the principle is that the microcontroller will continuously activate the usual steps until the current reaches the threshold value then the corresponding low side MOSFET will be activated and the white flag will be set this flag like the name implies stands for the white time which is recommended by the l6 two three four datasheet to be around 30 microseconds which is pretty close to the value of the commercial EC uses which is around 56 microseconds I however went with a value of 50 microseconds which I created by utilizing the timer to of the Arduino microcontroller all the timer interrupts then does is residing the white flag so that the usual steps can once again the activators but we should not forget to reset the timer to counter when the intermediate steps are activated after uploading the new codes and supplying power we can see that the rotor it doesn't fake move but not in a way that would be useful for anything and if we take peek at the power supply we can once again see that the current limit still gets reached quite frequently to fight the problem I measure the voltage at the analog pin six which represents the voltage drop across the current chance it was noticeable that the maximum voltage drops were around 1.2 volts which would equal around 6 amps that means that even though I utilize the small prescaler for the ADC which equals a sample time of around 5 microseconds the ADC was still too slow to react accordingly to solve this problem I added a comparative seer whose output connects the pin 3 of the Arduino and the potentiometer to the schematic this way by setting a threshold value of 0.2 volts with the potentiometer the comparator will pull its output high whenever the voltage drop of the current channels exceeds the threshold value we can then use the signal on pin 3 as an external interrupt which will set the white flag instead of the analog read function and thus speed things up quite a bit so after adding all the newly required components to the circuit uploading the new codes and retouching the motor it was time for another test run which turned out much better the rotation speed may not be as fast as the commercial ESC but it is definitely usable only problem was that if we take a look at the power supply we can still see a couple thousands of current spikes so once again I measure the voltage across the current shunts which reveals a rather normal looking behavior for the most part but on the other hand there seems to occur of the current flow sporadically which doesn't get interrupted even though the external interrupt pin got pulled high and that was the moment I said screw measuring I'm going to use an additional timer as a reference value I went at the time the current required to reach our previously utilized threshold value which was around eight microseconds then I simply set up the second timer to interrupt by utilizing a value of 16 which is around eight microseconds and set the white flag to the corresponding interrupt instead of the measuring and after uploading the new codes we can see that we finally achieved some decent results with only minor current spikes the motor actually rotated so well that I added the propeller to it and enjoyed the light breeze that I created but if you think that it can rotate fast enough to create a decent uplift then you are wrong because once a certain speed is reached the rotor gets stuck the reason for this unwanted behavior is quite easy to understand when you think about it so far we use timer one to switch between the six different steps motorcycle duration between 88 and 1.6 milliseconds that means we dictated when the next step should occur but what we didn't care about so far was at which point exactly the magnets reached ideal position to switch to the next step for that we would need a feedback system like Hall effect sensors that tell us where the rotor is currently located but since our bill DC motor clearly does not feature such sensors we have to use another technique called B EMF orbeck electromotive force as an example we power the coils a and C according to step one which we face be a pretty much floating in the air now according to the magnetic fields one magnet will move towards coil B which thus induces a positive voltage into it the perfect moment to switch to the next step would be when the magnet is just about to pass phase B which coincidentally is the moment the magnet starts and using a negative voltage into the coil so we can use the zero crossing point not only from phase B but basically from all the phases that are flowing during step as an indicator to move to the next step that is why I added a second comparator C connected the inverting input of the three Picard comparator stages through the virtual neutral point of the be a DC motor and connected each phase separately to each one of the 3-year non-inverting inputs of the comparators their outputs then connect to pin ten eleven and twelve and after soldering the additional components to the per port and connecting them to the rest of the circuits we can see that by utilizing the code we crafted so far the three outputs create a PWM signal which changes its output state whenever a zero crossing occurs so I set up a pin change interrupt on pin ten eleven and twelve and started altering the codes one last time now my optimization is rather crude and definitely not the best solution but it works acceptable well while I still use the timer one to generate a time in which the next step should occur I also utilize the new pin change interrupts at high rotation speeds to not only increase the on time for the current shopping but also increase the step counter prematurely if the floating phase of the motor it changes potential through the electromagnetic induction and to conclude this project let's upload the code one last time and see how well the motor rotates as you can see it still works very well at low speeds which is an advantage in comparison to the commercial ESC which can only operate at high speeds but on the other hands my dear ye is si cannot reach rotation speeds fast enough to create a sufficient uplifts but the reason for that is the increased current flow through the l6 2 3 4 driver which heats it up to a point where it starts to shut down a similar problem occurs when trying to use bigger bill DC motors which obviously require more current to rotate correctly so that is the point where you can use more modern ICS in combination with beefier MOSFETs to create a more powerful ESC but there is a subject for another video until then don't forget to Like share and subscribe consider supporting New York through patreon so that I can continue producing videos like this stay creative and I will see you next timewe ended the first part of this project with all Bill DC motor desperately trying to move for which the reason was that they current rise to it and the incapability of my power supply it to cover that demands to find a suitable solution now we already came to the conclusion that current chopping would be the way to go which was also confirmed if we have a look at the current curves while utilizing the commercial ESC to implement this feature the datasheet of the l6 2 3 4 presents us an application guides as soon as the current reaches the threshold value we simply deactivate the high side MOSFETs and activate the corresponding low side bottom so that the 2 coils are shorted to one another and thus decrease the current flow after said wait time the low side one then turns off the high side one reactivates empty current Rises through the coils once again until the process repeats so to start off the integration of this current chopping technique into the arduino codes i added six additional step functions which are pretty much identical to the counterparts except that instead of connecting one phase to the supply voltage they connect all phases to ground now to set a threshold value in which those intermediate steps are activated we can either measure the current through the motor or simply use an additional timer but since i already added current channels to the circuits to which the current of each phase will flow i will firstly try to measure the current eddy current flow of around 1 amp we get a voltage drop of roughly 0.2 volts across two resistors which once the voltage is measured by the analog pin a 6 equals value of 41 this will be a threshold value for the chopping and to activate it every move to do 1 flag for now and replaced it with a white flag in combination with an analog weed function before each step commands the principle is that the microcontroller will continuously activate the usual steps until the current reaches the threshold value then the corresponding low side MOSFET will be activated and the white flag will be set this flag like the name implies stands for the white time which is recommended by the l6 two three four datasheet to be around 30 microseconds which is pretty close to the value of the commercial EC uses which is around 56 microseconds I however went with a value of 50 microseconds which I created by utilizing the timer to of the Arduino microcontroller all the timer interrupts then does is residing the white flag so that the usual steps can once again the activators but we should not forget to reset the timer to counter when the intermediate steps are activated after uploading the new codes and supplying power we can see that the rotor it doesn't fake move but not in a way that would be useful for anything and if we take peek at the power supply we can once again see that the current limit still gets reached quite frequently to fight the problem I measure the voltage at the analog pin six which represents the voltage drop across the current chance it was noticeable that the maximum voltage drops were around 1.2 volts which would equal around 6 amps that means that even though I utilize the small prescaler for the ADC which equals a sample time of around 5 microseconds the ADC was still too slow to react accordingly to solve this problem I added a comparative seer whose output connects the pin 3 of the Arduino and the potentiometer to the schematic this way by setting a threshold value of 0.2 volts with the potentiometer the comparator will pull its output high whenever the voltage drop of the current channels exceeds the threshold value we can then use the signal on pin 3 as an external interrupt which will set the white flag instead of the analog read function and thus speed things up quite a bit so after adding all the newly required components to the circuit uploading the new codes and retouching the motor it was time for another test run which turned out much better the rotation speed may not be as fast as the commercial ESC but it is definitely usable only problem was that if we take a look at the power supply we can still see a couple thousands of current spikes so once again I measure the voltage across the current shunts which reveals a rather normal looking behavior for the most part but on the other hand there seems to occur of the current flow sporadically which doesn't get interrupted even though the external interrupt pin got pulled high and that was the moment I said screw measuring I'm going to use an additional timer as a reference value I went at the time the current required to reach our previously utilized threshold value which was around eight microseconds then I simply set up the second timer to interrupt by utilizing a value of 16 which is around eight microseconds and set the white flag to the corresponding interrupt instead of the measuring and after uploading the new codes we can see that we finally achieved some decent results with only minor current spikes the motor actually rotated so well that I added the propeller to it and enjoyed the light breeze that I created but if you think that it can rotate fast enough to create a decent uplift then you are wrong because once a certain speed is reached the rotor gets stuck the reason for this unwanted behavior is quite easy to understand when you think about it so far we use timer one to switch between the six different steps motorcycle duration between 88 and 1.6 milliseconds that means we dictated when the next step should occur but what we didn't care about so far was at which point exactly the magnets reached ideal position to switch to the next step for that we would need a feedback system like Hall effect sensors that tell us where the rotor is currently located but since our bill DC motor clearly does not feature such sensors we have to use another technique called B EMF orbeck electromotive force as an example we power the coils a and C according to step one which we face be a pretty much floating in the air now according to the magnetic fields one magnet will move towards coil B which thus induces a positive voltage into it the perfect moment to switch to the next step would be when the magnet is just about to pass phase B which coincidentally is the moment the magnet starts and using a negative voltage into the coil so we can use the zero crossing point not only from phase B but basically from all the phases that are flowing during step as an indicator to move to the next step that is why I added a second comparator C connected the inverting input of the three Picard comparator stages through the virtual neutral point of the be a DC motor and connected each phase separately to each one of the 3-year non-inverting inputs of the comparators their outputs then connect to pin ten eleven and twelve and after soldering the additional components to the per port and connecting them to the rest of the circuits we can see that by utilizing the code we crafted so far the three outputs create a PWM signal which changes its output state whenever a zero crossing occurs so I set up a pin change interrupt on pin ten eleven and twelve and started altering the codes one last time now my optimization is rather crude and definitely not the best solution but it works acceptable well while I still use the timer one to generate a time in which the next step should occur I also utilize the new pin change interrupts at high rotation speeds to not only increase the on time for the current shopping but also increase the step counter prematurely if the floating phase of the motor it changes potential through the electromagnetic induction and to conclude this project let's upload the code one last time and see how well the motor rotates as you can see it still works very well at low speeds which is an advantage in comparison to the commercial ESC which can only operate at high speeds but on the other hands my dear ye is si cannot reach rotation speeds fast enough to create a sufficient uplifts but the reason for that is the increased current flow through the l6 2 3 4 driver which heats it up to a point where it starts to shut down a similar problem occurs when trying to use bigger bill DC motors which obviously require more current to rotate correctly so that is the point where you can use more modern ICS in combination with beefier MOSFETs to create a more powerful ESC but there is a subject for another video until then don't forget to Like share and subscribe consider supporting New York through patreon so that I can continue producing videos like this stay creative and I will see you next time