Electronics > Beginners

Controlling the speed of a DC motor

<< < (4/4)

planet12:

--- Quote from: pepelevamp on July 23, 2019, 10:56:52 am ---
--- Quote from: planet12 on July 20, 2019, 04:03:57 am ---What I found to work well in the end was to take a number of samples, sort them, then take the median (NOT the mean/average). This removes the outliers from the mix, and gave me a stable speed with quick response to changing load. I'm taking 15 ADC samples - this was empirically determined with the speed range and motor I was using once everything was put together - you want to sample enough over a long enough period so that your median value is useful).

--- End quote ---
hahaaa dude thats actually pretty clever. with regards to the median - did you count each ADC value once and then look for the median value?

--- End quote ---

I just looked at the code to remind myself.

I disabled the motor PWM, then took 15 successive samples into a uint16_t array. Once completed, I qsort'ed them and used the middle of the array - adc_readings[7] - and fed that into the PID, then re-enabled PWM using the new motor setting from the PID code.

In retrospect, I could probably have hooked up the scope and figured out a reasonable settling time instead, but this seemed to work well. I suspect I only had my old 1960's analogue scope at the time, rather than my shiny DSO - t'was almost a decade ago now  :D

Navigation

[0] Message Index

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod