I am driving a three phase Brushless DC motor with Arduino Mega. I am using sensored six-step commutation with Hall effect sensor. Currently, I am controlling speed of the motor with three buttons - one for clockwise rotation, one for counter-clockwise rotation and one is used as a STOP button. I am using L6234 (μP compatible three-phase inverter, schematic is here) as an output energy source for the motor.
I also measure current and RPM and send it to Arduino IDE Serial monitor every second. But when the motor is rotating and I click on a Serial monitor icon, it suddenly stops and I do not know exactly why. I think that the Arduino program restarts when you turn on the Serial monitor but I am not sure and a hint what is really going on would be useful, especially to prevent some damage to the motor or the Arduino. But this is not a serious problem, cause I can always start the motor before using the Serial monitor...
I also wanted to implement a PID controller (my own, not the library). I tried to send the desired PWM duty-cycle (the duty-cycle was directly written to PWM registers without PID) via Serial monitor. It worked fine when the motor was still. But when the motor was rotating and I sent a new duty-cycle, the motor stopped and then it began to rotate with the new speed. I used Serial.available() to check for the new data and Serial.parseInt() to convert the text into integer, nothing more.
Without solving this I cannot start with the PID controller and I really do not know where the problem could have been. I would be really grateful for any suggestions. Complete sketch and a hardware schematic is in the attachment.
When you open a serial connection (to the first serial port, the one named Serial and used for uploading), the Arduino is automatically reset (so that if you're opening this connection to upload a sketch, the bootloader will run and you can upload the sketch).
The standard way to disable this is to put a ~10uf cap between ground and reset on the Arduino (you will want to remove this cap when uploading new code). Exact value of the cap isn't critical (math + spec sheet suggests that 1uf would be sufficient - but you want to err on the side of a larger cap)
Thank you. And, concerning my second question, do you have an idea why the motor stops when I send a new duty-cycle from Serial monitor which is already on?
lipcaond:
Thank you. And, concerning my second question, do you have an idea why the motor stops when I send a new duty-cycle from Serial monitor which is already on?
Serial.parseInt returns a value that you happily seem to ignore. Not said that that is the reason but definitely something to look at.
So I don't even understand how it could work the first time.
sterretje: Serial.parseInt returns a value that you happily seem to ignore. Not said that that is the reason but definitely something to look at.
So I don't even understand how it could work the first time.
I forgot to write down, that the motor started to spin with some delay. So, what happened was, that I sent a new PWM duty-cycle to spinning motor, the motor immediately stopped and then with approx. one second delay it began to spin with speed corresponding to the new duty-cycle. As if Arduino read 0 first and then it "switched" to the sent value.