PWM channels for DRV1 Is the TIM1 and for DRV2 it is TIM8. The doubt i have is with the current sense. I have enabled the ADC1 IN1234 and ADC2 IN 3 and 4 i can’t enable the lower channel pins of ADC2 since it conflicts with the ADC1 pins.
In order to get the current sense working the 3 ADC should belong to the same channel right? is there a way i can achieve this? Or should i use the higher channel for the second driver and my option is ADC2 IN3, IN4, IN10
will this become an issue?
Interesting question I’d have to check the manual to be sure, but I’d guess it will just force one of them to wait until the other is finished. Or you could use PA7, PC4, PB2 (ADC2 channels 4, 5, 12) to avoid the issue.
By the way, here’s my handy reference for which pins are which channels. This is the UQFPN48 package, so there are some small differences from your LQFP48, but which ADC channel goes to which name like PB2 is the same across all packages.
many MCU types don’t have enough pins or ADC resources to do it
On other MCUs, which could do it in practice like the stm32g4s, the setup becomes much more complex and the user (as you are discovering) has to be very careful about the pins and peripherals used…
So at the moment we don’t support multiple motor current sensing, but we probably will support some cases in future, and stm32g4 will most likely be among the first.
The DRV8316 is low side sensing IIRC, but it’s quite a complicated chip.
From my point of view for low side sensing on two motors it’s probably better to use ADC1 (3 channels) for motor 1 and ADC2 (3 channels) for motor 2. Of course it can also be ADC3, the point is 3 channels of the same ADC per motor.
In this way you can operate them independently, and the motors won’t interfere with each other even if the PWM of both motors is in phase.
The disadvantage is that the channels have to be sampled in sequence and for some PWM duty cycles close to 100% you may not have enough time to sample all 3 phases.
The other option is to use one channel of each of ADC1,2,3 for each motor.
Then you can sample the phases in parallel, but then for two motors you will have to make sure the PWM of two motors is out of phase to be sure they won’t interfere with each other, and the setup of the ADCs and DMA will be very complicated…
It just means you’ll have to write your own ADC code, which is not terribly difficult. I’d recommend changing PA3 to PA4 (ADC2_IN17) or PB2 (ADC2_IN12) so the second motor can use all ADC2 channels to keep the code cleaner. Channel numbers don’t need to be consecutive or ascending order or anything, the sequence registers can convert them in any order you like. The only limitation is that in dual mode, ADC1 and ADC2 can’t convert the same channel number at the same time. But you shouldn’t have to worry about that. Read the ADC section in reference manual rm0440. There are also a couple of RCC bits you have to enable at startup. See my code here, although I haven’t actually verified that it works yet: Gooser: a 4-in-1 Lepton derivative - #21 by dekutree64
Yours will be simpler in some ways since you don’t have linear hall encoders mixed in, and won’t need dual mode. Just set them up independently to read their 3 channels when triggered. But also more complicated that you’ll need to figure out how to trigger it off the timer for low-side sensing, unlike my inline sensors where I can just set ADC_CR_ADSTART from the main loop.
How do i make sure that they don’t sample at the same time if i choose the same channel number in both of the ADC1 and ADC2 like i’m using ADC1 IN3 and ADC2 IN3?
The F103s have 2 or 3 ADCs, so I think it would be possible, with the same comments applying as above:
if you select a configuration with all phases of a motor on the same ADC, you have to sample the phases in sequence, but (especially if its inline sensing) can use the ADCs independently, not needing complex coordination.
if you select a configuration with each phase on a different ADC, you can sample all phases in parallel, which will get you the best performance. But it’s complicated to set up both from the pins to use and the software config (esp for low side sensing).
I think the most compatible and easiest to configure setup is inline sensing with one ADC per motor.
Section 8.3.10.5 Four Level Input Pin, Page 36 of the reference manual.
For Hi-Z connect 5Mo to analog ground, or may be leave open (no connect). Pick a large size like 805 or even 12 to desolder if you choose to go with 5Mo and that’s not high enough. I usually put two, one to VDD another GND and leave them open to solder my own to test different scenarios. That’s gonna make your board a little busy though.