9 years, 11 months ago.

Perform program speed control of a DC motor which is handled with the capacitive sensor FRDM-KL25Z

/media/uploads/alberto12/motor_dc.jpg

1 Answer

9 years, 11 months ago.

Hi Alberto and welcome!

I don't have a FRDM-KL25Z so my help will be very general.

I will assume that you will control your motor speed using a PWM signal on the ENABLE pin? The easiest way to do it is to follow the following:

General code to control Motor Speed using any sensor

#include "mbed.h"

AnalogIn sensor(pin);  // Capactive sensor for FRDM-KL25Z
PwmOut motor(pin);    // Connect to ENABLE pin on your motor driver

// Connect these 2 is you have the option of controlling motor direction:
DigitalOut directionA(pin);
DigitalOut directionB(pin);

int main(void)
{
    while(1) {
        motor = sensor.read();
        wait_ms(20);
    }
}

Essentially:

  1. Read capacitive sensor. Should be an analogue read.
  2. Output value read from sensor as dutycycle of a PWM pulse.

Once you get to advanced control, you can start working with uint16 value from sensor instead, and to also consider the period of the pulse in order to achieve whatever design objective you have.

Good luck! Ian

Accepted Answer