David,
Thank you very much!!!
I’ll also try to locate sensor with SPI (I know my soldering skill is no way good enough for this tiny sensor that I have & tap into SPI out pins with wire)
David,
Thank you very much!!!
I’ll also try to locate sensor with SPI (I know my soldering skill is no way good enough for this tiny sensor that I have & tap into SPI out pins with wire)
If anyone is interested in this topic, I think the problem here is that the AS5048A is easily available for about $8 on AliExpress, but the modules always come with PWM output wired, and SPI output on an impossible to solder set of tiny solder-leads…
I had the same problem. First I ordered the Test Modules from AMS: AS5048AAdapterBoard | ams (EUR 15)
But these are a little bit big. In the end I solved it by creating my own board for this, and I used the AS5048B - I prefer the I2C interface, its easier to wire up with only 4 leads.
Hey guys,
If someone has time to implement a PWM version of this sensor we would be very happy to include it to the library.
We do have it in our plans to make it but it being postponed every time by some other “more interesting stuff”
Antun,
Thank you very much calling out for attention call!
I’d assume there would be limited interest on this PWM input method from Raspberry user & perhaps from Arduino side.
If you can consider quite bit of vision processing or developments involve Raspberry PI 3, 4 and other product requiring Pan & Tilt Servo and also requires PWM output.
Wondering, isn’t that give you all enough reason to cover this subject?
I’ll be honest, If there is no PWM support, I have very little reason to study FOC board and perhaps no reason to re-visit this site at all.
Is this site shut out for HW developer only for deveoper’s interest only, or are you or someone else looking into software support side in broad including PWM input issues?
I’d assume to support wider platform, in order to sustain development support & continuance, or is it just me barking at?
Hey @Martin-Kim.
Everyone has their own reasons to use this library and I’m perfectly aware that it does not suite everyone’s applications.
And once again, the goal of this library in is not to suite everyone’s applications be optimal the goal is to enable people to use start using foc simply on as many hardware setups possible.
Honestly servo like PWM input for this library is not really something we are interested in at the moment. At least not to implement into the library. But I’m very sure with a little of search you can find a library which decodes the owl signal and then you can use the decoded signal directly with the simple foc.
Now in terms of PWM sensors that we will implement. Maybe not very soon, because we are entirely in dev phase for current control but it will be done. Again because the pwm sensor is important for field oriented control.
That’s completely undertandable, but again. PWM support is for me outside the scope of this library and I am pretty sure you can find a good pwm reading open-source code pretty easily and then use the decoded values with simple foc if you wish to use BLDC motors.
I’m not sure that I follow what you mean here. This site is for all discussions related to hardware and software issues/extensions/applications. It is open to any type of discussion and we are always happy to hear all the sides and we are adapting our development both hardware (simplefoc shield) and the software.
Now, this project is an open-source project and we are a team of three spread all over the world. We all have jobs and things we work on this whole project it our spare time. We try to spend as much time as we can on it but sometimes it is dificult to implement and develop all the features that are important (sw and how). And also it is dificult to decide what features are important.
So for us the community size we have at the moment is already a great achievement and we are hapy that we are enabling people to use field oriented control in a simple maner!
Anton,
So true, I was lost after many unsuccessful attempt & became selfish and owe you apology.
Thank you all very much for what you do for community.
Newb here. This thread is from 2020. Has PWM been implemented into simpleFOC? 100% all of my use cases would be controlling BLDC motors with PWM. Thanks in advance.
I don’t think there’s any library code, but here’s what I normally do:
#define SERVO_PULSE_PIN PA15
volatile uint16_t servoPulse = 1000;
void ServoPulseUpdate() {
static uint32_t startTime = 0;
uint32_t curTime = micros();
if (digitalRead(SERVO_PULSE_PIN)) // Pin transitioned from low to high
startTime = curTime; // Start counting pulse time
else // Pin transitioned from high to low
servoPulse = (uint16_t)(curTime - startTime);
}
void ServoPulseInit{
pinMode(SERVO_PULSE_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(SERVO_PULSE_PIN), ServoPulseUpdate, CHANGE);
}
Or if you need more than one input and/or calibrated values, here’s a more complete class I wrote.
class ServoPulse {
public:
int16_t calLo = 1000, calHi = 2000; // Caibration values, min/max pulse time in microseconds
float min = -1, max = 1; // Output range
void init(int p, void (*func)()) {
pin = p;
pinMode(p, INPUT);
attachInterrupt(digitalPinToInterrupt(p), func, CHANGE);
}
float getVal() const {
int p = pulse;
p = _constrain(p, calLo, calHi);
return min + (p - calLo) * (max - min) / (calHi - calLo);
}
void irq() {
digitalRead(pin) ? startTime = micros() : pulse = (int16_t)(micros() - startTime);
}
private:
uint32_t startTime = 0;
volatile int16_t pulse = 1500;
uint8_t pin;
};
ServoPulse speedKnob;
void SpeedIrq() {
speedKnob.irq();
}
void setup() {
speedKnob.init(PA15, SpeedIrq);
speedKnob.calLo = 884, speedKnob.calHi = 2084, speedKnob.min = 0, speedKnob.max = 65;
Sorry, I should have been more clear. I would be using BLDC with simple foc stm32 and encoder motors as hobby servo replacements, in closed loop angle mode with only needing speed and position, maybe torque (180 degrees of motion max with pulses between 1000 and 2000 ms with 1500 at zero.) I’m trying to use this setup with animation software that supplies PWM signal. Will the first part of your code do that?
Yeah, if you just need the raw pulse time then that first code block will do it.
Hi @fxrtst , welcome to SimpleFOC.
Actually we have PWM sensor support, please see the MagneticSensorPWM class.
We also have PWM out support (for controlling servos) in the SimpleFOC DC motor library.
And we have extra support for STM32 MCUs for PWM in via hardware peripheral of the MCU, so on STM32s you can do it without CPU overheads or interrupts.
That said, we always recommend against using PWM sensor inputs:
Since i see you’re planning to use STM32, please take a look here:
You’d have to wrap that in a GenericSensor class to use as sensor. But really, I don’t recommend PWM for sensors.
Thank you very much for the reply!
Thank you for all this info and links. What a great community! The software I am using for my animatronics is called Bottango. The program basically outputs PWM data from animations you create in the UI to any arduino with servos attached. My goal is to replace the servos with BLDC motors. Bottango produces live output via PWM from the computer usb port or can be exported and played back by an SD card on the arduino. A successful test will let me know if the resolution will be good enough. I’ve even contemplated attaching servos to pots that are attached to the stm32 in closed loop for a poor mans, digital to analog to digital solution…lol!
Any additional help/ideas and advise for a newbie is always be appreciated.
Ok in this case the PWM is being used for position control and not as the sensor signal.
So for this use case, especially on STM32, the STM32 PWM Input code I linked would be the one to use if you want the STM32 to read in a PWM signal produced by the computer or an Arduino.
You would then map that PWM input value to a SimpleFOC target position for the motor control in position mode, to emulate the servo…
THANK YOU very much!