Howdy Smart People. I am looking to set up a few buttons to control command.add(‘T’, doTarget, “target velocity”);
My Arduino skills are lame at best, so I am inquiring if anyone has set up a few momentary buttons to fire off velocity commands.
I am finishing a turntable that is working quite well in open loop but need to set up zero, 33, 45 and 78 speeds. Currently at 33 1/3 the turntable is exceeding expectations.
Basic code to react to a button might look like this:
// define some constants for the
#define SPEED33 3.5f
void loop() {
// button on pin 15
if (digitalRead(15)==HIGH) { // high state means on
motor.target = SPEED33; // this button sets the speed to 33.3rpm
}
...
}
this code is still very primitive, but you get the idea.
if you’re using an external variable in your doTarget() rather than setting motor.target directly, that’s fine too, just set that one via the button
you probably don’t need to check the buttons every time through the loop. Build in a counter or timestamp and check them only 10x per second or so
you may also need to add some “debouncing” or take some measures like requiring a minimum time between accepting new values - this is usually needed to improve the useability for the user, since pressing the button often results in multiple triggering of the actions if you’re not careful. Depending on how your code works this can be confusing/difficult for the user.
Many, many thanks. I will get on that. There is no way this project could be happening without SimpleFOC. There are other sine wave bldc drive solutions, but nothing as simple, solid and cost effective.
Jazzboy - good to see you on this forum. I have seen your turntable on DIYAudio. Nice job.
You probably also want to add up/down buttons or a rotary encoder to adjust the motor speed slightly around the preset motor speed to get to exactly 33.33 platter speed. Belt wear, size, etc can affect the platter speed substantially. (I am working on a similar turntable project as well).
I have also considered putting an encoder on the platter itself, and monitoring that to calculate platter speed in real time, and send adjustments over to the motor controller during initial spin up to make sure it is dialed in. Kind of like a modern day Quartz Lock.
You could certainly do what you describe! You could run SimpleFOC in torque-voltage mode, while running another velocity control loop on the platter’s sensor…
You could re-use the SimpleFOC Sensor, PID and LPF classes for this purpose.
Oh interesting! Are you suggesting that instead of Open Loop Velocity control on the motor running the pulley and belt, instead use Torque Mode closed loop? And then use the encoder on the platter (which runs at say 1/10th the speed of the motor) to provide feedback to the torque control on the motor to regulate speed of the platter?
Many thanks. Very good ideas. For now, my programming chops are weak but as I get better, I will implement more control. The Quartz lock idea is very good.