how many SPI or alternative devices with STM32F103C8T6

Post here first, or if you can't find a relevant section!
Post Reply
navanod
Posts: 15
Joined: Thu Jun 11, 2020 3:27 pm

how many SPI or alternative devices with STM32F103C8T6

Post by navanod »

I prototyping a project using multiple magnetic sensors that either use SPI, SSI, I2c..encoded PWM or quadrature output..that's a mouthful.
Trade offs with this project are simply cost, I need a lot of sensors (hundreds)

The cheaper of the sensors such as the as5600 or as5200l have i2c but they are not that ideal as the as5600 had some dead banding and the a5200l has either i2c or the encoded PWM.

with some effort I could get the encoded PWM output but I am suspicious of the noise(as I am with the i2c). The SSI from an as5040 works fine and I also have some as5048s and as5047 that can do quad a, b and I outputs. The as5048 and as5047u are not cheap though at 10 euros a pop

If i went with say the as5047D then I can get the price down a little, but as far as my knowledge leads me to believe this would require 3 separate SPI channels on the blue pill or am I mistaken?

my aim is using the blue pill along with an esp32 spi master to also handle the communication.



Thoughts? Anyone have any other suggestion for other magnetic encoders that might do the job for FOC that could work with the blue pill?
Here are some of the datasheet links in case its an interesting subject
https://ams.com/documents/20143/36005/A ... 6245475079

https://ams.com/documents/20143/36005/A ... f52c962099

and some other lists of the AMS sensors
https://ams.com/angle-position-on-axis
ag123
Posts: 1657
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: how many SPI or alternative devices with STM32F103C8T6

Post by ag123 »

normally spi is selected by using the ss or cs pin, so presumably if you can multiplex the cs pins u can have many devices on a single bus?
i think the other issue is normally spi can clock up to PCLK/2 e.g. 72 mhz / 2 ~ 36 mhz.
for the faster devices they probably can handle 36 mhz, but there are slow devices that probably can't handle that

for multiplexing one 74hc4067 drives 16 channels
https://assets.nexperia.com/documents/d ... CT4067.pdf
or you can even try 74hc595 shift register which can daisy chain into a large number of channels
https://assets.nexperia.com/documents/d ... HCT595.pdf

another interesting way though is to do *analog*
https://www.sunrom.com/get/324700
i'm not too sure if 74hc4067 can be 'abused' for that purpose, i.e. use as an analog multiplexer
if that is after all feasible and stm32 has internally multiplexed 8 adc channels, using that you may be able to multiplex 8 x 16 ~ 128 analog channels
but of course analog is somewhat dicy if long wires are used
navanod
Posts: 15
Joined: Thu Jun 11, 2020 3:27 pm

Re: how many SPI or alternative devices with STM32F103C8T6

Post by navanod »

Hey thats very helpful information thank you. I think I will get my hands on some of those devices you mentioned for testing things out.
I guess I should also clarify that each of the things I am building use 3 magnetic sensors per robot..perhaps thats more feasible to think about 3 on the blue pill and toggling the Cs

Not having much luck so far with the AS5600 though, its either some crappy i2c/i2c not being fast enough or that the implementation of the table array for commutation within the library am using isnt suitable with the blue pill.

Im using the arduino FOC https://github.com/askuric/Arduino-FOC

Ive tested this with both a normal encoder with quad output, a as5040 and the as5600. So far the as5040 seems to do a better job at smooth commutation but thats with an arduino nano.

im using bp0 bp1 and pa7 for the 3 signals..they seem to be hardware PWM so I thought it should be good? I gave them set up at 50KHz but oddly can still hear some tone from the motor..not expected but my scope also says 50k so weird
ag123
Posts: 1657
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: how many SPI or alternative devices with STM32F103C8T6

Post by ag123 »

note that ss49e is not a very sensitive field effect sensor
https://www.youtube.com/watch?v=Mj5ukCVP1LQ
the magnet needs to be pretty close for the sensor to detect it (see video)
if cost isn't too much an issue and that if you can buy *real* (not fake) stm32f103 pill boards for a low cost
you may even want to simply interface the sensor directly to the ADC, PA0 - PA7 (8 analog inputs).
stm32 adcs has a scan feature in which it can scan the adc pins one after another - the built-in multiplexer.
so in that sense one stm32 pill board can do 8 channels. that multiply easily say if you have 10 boards
and you literally have a spread of 80 sensors.and fast adc. you would then need to bridge those to a pc say usb-serial? so 10 cables and you can poll 10 stm32f103 pills for 80 sensors, the pill boards can probably store some results in that 20k sram and foward them when polled.

a good thing is those sensors seemed to cost rather moderate, even if it may not be very sensitive
https://www.aliexpress.com/wholesale?ca ... Text=ss49e

if you need more than 8 channels per adc, then you may need to mess with the multiplexers. i'm not too sure how well they would work with analog signals.

as i've not literally worked with a as5040, all that i could say are guesses and based on the specs i read
https://ams.com/as5040
it would seemed the digital interface may be easier to interface and it looks like some sort of spi like protocol
and with those 74hc4051, 74hc4067 etc, the CS signals can be multiplexed easily
edit: i read the specs a little further, it seemed as5040 has a daisy chain mode, with that you won't even need the multiplexers, it seem possible to daisy chain a series of as5040 and read them off a single spi bus with just 3 pins d0 , clk , cs

i'm thinking it may be possible to reproduce the workings of an as5040 by using ordinary analog field effect sensors placed at 90 degrees around a rotating magnet
https://www.fierceelectronics.com/compo ... y-encoders
but of course as5040 is a professionally designed product and calibrating analog sensors and doing all that calcs can itself be a big challenge.
Post Reply

Return to “General discussion”