05-06-2020 04:14 PM
I searched around and didn't find quite what I was looking for.
I'm working on a project that uses a STM32 microcontroller but it didn't satisfied my needs.
So I want to use a fpga that works hand in hand with STM32. I need the fpga to work as slave and make pwm or I/O control. I need them connect through SPI or UART.
Problem is I get lost searching in Google and now I'm confused.
I need some kind of example and documentation to get The Big Picture and understand the hole thing before getting started.
What is the best way to do this?
Thanks a lot.
05-06-2020 05:14 PM
Can you expand on how the STM32 didn't satisfy your needs? An FPGA represents a large and complex solution, and if the problem is just that you need a few more timers and I/O pins then the easiest solution is almost certainly just a bigger STM32 chip.
With that said, if you want to continue with the FPGA:
- Get some experience with using the STM32 to talk to other SPI devices. The FPGA design will almost certainly end up looking a lot like the register map of something like an LSM9DS1 - a bunch of registers, some of which can be written to configure the device, others that can be read to query its status, plus a couple of dedicated interrupt lines.
- The FPGA internal design is basically going to be the same as what you're used to with the STM32 (ie writing registers to set up and control timers or GPIOs). However, as you will have just experimented with above, controlling those registers is done over SPI instead of directly.
- The PCB layout will just have the two chips, four SPI lines (SPI is recommended over UART), and probably one or two interrupt lines too (so the FPGA can tell the STM32 if it needs to pay attention).
05-07-2020 04:27 AM - edited 05-07-2020 04:27 AM
Thanks for answering
I think I get the idea, I guess it works something like Modbus. you name a register then assign a value, and on the FPGA side, I need to make timers by my self! right?
I guess there is no built-in timer or PWM generator.
One more question, since there is no easy way to count the stm32's PWM numbers(without using another timer/counter) I ran out of Timer in STM32. for example, If I need to control a 6 axis CNC machine with PWM I can use 6 timers to generate PWM, then I need 6 more timers to count them. something like this uses a lot of STM32's resources.
How is that done in FPGA?
05-07-2020 06:06 AM
You're correct, there are no built-in timers or PWM generators - or anything else. However, PWM generators and timers are very easy to create in an FPGA. A timer is just a counter. For PWM generation, you just need to compare the timer to a constant value - when the timer is less than that value the output is on, when the timer is more than that value the output is off. You can add a prescaler to reduce the input clock of the timer if necessary, since most external applications don't call for a 100MHz timer clock. From there, you can add a second counter to count how many times the timer has overflowed. This counter can be used as an index into a RAM, so that each time the timer overflows the constant compare value gets updated. In an FPGA, none of these is difficult to implement - all the complexity is in the interface (if you want the timers to read from RAM, the microcontroller has to program that RAM first, over a relatively slow SPI bus...).
With regards to the STM32 project - a couple of points:
- Are you doing true PWM (ie actively modulating the PWM level between 0% and 100% to send a certain amount of power to a motor), or are you doing servo PWM (eg. 1-2ms pulses sent at 40 - 50Hz to set a servo position), or are you just sending steps to a stepper motor driver? Generally for the first two, you don't really care exactly how many pulses have been sent; for the first one there needs to be an external feedback mechanism (eg. an encoder) because the number of pulses sent has no relation to how far the motor has moved, and for the second one the value of the pulse sent (rather than the number) defines exactly where the actuator is. The remaining case does require you to count steps, but it requires CPU intervention at every step (eg. for acceleration and deceleration, on each step you need to change the timer top value). Since it tends to only run at ~10kHz, any of the STM32 chips can easily keep up with counting how many steps have been done.
- Which chip are you using? A bunch of them have Advanced Control timers that allow you to say "run at <x> PWM value for <y> cycles". Also, most of the timers have multiple PWM outputs. The chip I've got my eye on is the STM32H7B0 - this has two advanced control timers (each with four PWM outputs) plus ten general-purpose timers that have a total of 24 PWM output channels between them.
Don't get me wrong, the FPGA will do all of this efficiently and elegantly - but it's going to make the development side much more complicated (for both hardware and software) and so I'd fully explore all other options first.
05-07-2020 07:52 AM - edited 05-07-2020 11:09 AM
I want to control servo motor with steps. but 10kh is not even near enough. A DELTA SERVO MOTOR, for example, has one million and two hundred thousand steps per revolution , although I can reduce it to lower resolutions, still, I need to go on the safe side, so let's say I need least 1MHz pulse per second to run a servo motor to reach some acceptable speed on a linear axis, and I have also five other motors to control at the same time.
there is also a TFT LCD and sensors too.
STM32F4xxx TIMERS has multiple channels but they aren't capable of generating PWM at different frequencies at the same time.
What I found was if I want to generate some pre-defined number of pulses with PWM, I have to use another timer to count them and generate an interrupt when the TIMER reached my number but this way where will be a lot of timers interrupts and they will intercept each other and there is a great chance of making some extra pulse.
05-07-2020 05:59 PM
Wow, 1.2M steps per revolution? That explains a lot. There are ways to get multiple PWM frequencies from a single timer on a microcontroller, but an STM32 may well struggle to generate multiple PWM channels at that speed, especially if you want decent resolution.
An FPGA should be able to do what you require very easily. Additionally, while the FPGA represents a large cost for a hobby-grade project, I suspect that it pales in comparison to what you're spending on the servos.
05-08-2020 04:35 PM
Thanks a lot
You have been great help.
I'm gonna get a board and start playing around To see what happens.