0

I have a timer set up in the cube to make a PWM... Just setting ARR and CCR to different values.

I'm using the callback functions for both events that HAL set up for me, I think one is for the CCR compare event and the other is for the ARR compare event.

Anyway, in both of those I'm toggling a GPIO port like this:

GPIOC->ODR = foo;

Anyway, I want to sample the values of 3 ADC1 channels during the high pulse, but I'm not sure how to do that accurately. I'm using DMA in circular mode with the ADC1 right now.

I don't want to sample immediately after setting the pins, because there's propagation delay, noise, etc.

So, I want to: Set the pins, wait a very short and constant amount of time, sample all the channels and then do some math on the results.

This is for a Bldc motor controller, by the way... Im trying to sample the BEMF on the positive side of the PWM drive signal, and I'm driving it at 18khz, 5% duty cycle, so my pulse lasts for 2.7us.

I'm not sure how to handle or debug this because it's so timing related and I need the motor to deliver the signal that I'm using... If the motor isn't spinning, then there's no feedback signal to work on. It sure seems like I'm trying to do too much in the timer ISRs, though.

Sorry I can't post any code right now... Im at the grocery store, but I'll put some up when I get back.

testname123
  • 1,061
  • 3
  • 20
  • 43
  • 1. You are not toggling you are assigning. 2. Trigger another timer which will trigger after some time your ADC. 3. HAL is the evil and I am 100% sure that you will learn very quickly how bad it is. – 0___________ Oct 29 '17 at 01:41
  • Why don't you want to continuously sample the inputs into memory and select the right sample by software? This way you can also implement additional filtering. – A.K. Oct 29 '17 at 02:14
  • A.K. I love it, but how do I know what sample is in SRAM when I go to get it? Isn't it autonomous? – testname123 Oct 29 '17 at 04:13
  • I don't want to read what's in there and find out it's old news, or worse, not fully transfered yet – testname123 Oct 29 '17 at 12:29
  • I meant you read several samples with DMA and after they are all done, choose the n-th one, or take an average, etc. However, which MCU do you use and at what frequency? You seem to start every PWM cycle from the CPU. Why don't you let it run from a timer continuously and only adjust the duty cycle when needed? – A.K. Oct 29 '17 at 14:53

0 Answers0