rjsdotorg
Well-known member
I have a small BLDC motor (5 wire with internal control board) and doing PWM control.
As per the Teensy docs:
Ie,
analogWriteFrequency(nnnnn) does not affect it.
What does teensy_slow_pwm do? Anything helpful? SoftPWM does not look helpful.
Will https://shawnhymel.com/649/learning-the-teensy-lc-manual-pwm be of use?
If anyone has suggestions - I'd like to hear, otherwise I'll work around it...
I was a little concerned about ground potential difference between the 12V wall wart and the laptop USB power, but tying them together does not seem to affect anything at all.
As per the Teensy docs:
Anytime you are doing PWM at high duty cycle it glitches every 4.3-5s, with exactly 500Hz. This is with or without a 4.7k pull-up.Vales 0 and 256 are meant to correspond to logic low and high. However, the PWM hardware may not be capable of truly 100% low or high. A very short pulse may occur between each PWM cycle where the pin is driven to begin a new cycle, and then very quickly changed because the setting attempts to keep the pin always low or always high. To avoid any small glitch pulses, the pin may taken out of PWM mode using pinMode() and then controlled by digitalWrite().
Ie,
analogWrite(2, 255); enables it - actually >=240 causes the action, while 239 is a slow roll and 256 a true stop.analogWriteFrequency(nnnnn) does not affect it.
analogWrite(2, 0); runs smoothly.What does teensy_slow_pwm do? Anything helpful? SoftPWM does not look helpful.
Will https://shawnhymel.com/649/learning-the-teensy-lc-manual-pwm be of use?
If anyone has suggestions - I'd like to hear, otherwise I'll work around it...
I was a little concerned about ground potential difference between the 12V wall wart and the laptop USB power, but tying them together does not seem to affect anything at all.
Code:
# Teensy BLDC Motor Controller with Speed Feedback
This project controls a BLDC motor with built-in driver using a Teensy 4.x microcontroller, providing PWM speed control, direction control, and speed feedback monitoring.
## Hardware Connection Diagram
```
┌─────────────────────────────────────┐
│ Teensy 4.x │
│ │
│ Pin 2 (PWM) ──────────────────┐ │
│ │ │
│ Pin 3 (DIR) ──────────────────┼──┐ │
│ │ │ │
│ Pin 4 (Frequency) ───────────┼──┼─┼──┐
│ │ │ │ │
│ (Common Ground) ──────────────┼──┼─┼──┼──┐
│ │ │ │ │ │
│ │ │ │ │ │
└────────────────────────────────┼──┼─┘ │ │
│ │ │ │
│ │ │ │
┌────────────────┼──┼────┼──┼────────────┐
│ BLDC Motor │ │ │ │ Controller │
│ WHITE wire ◄──┘ │ │ │ (PWM) │
│ GRN wire ◄─────┘ │ │ (DIR) │
│ YELLOW wire ◄──────────┘ │ (FG) │
│ BLACK wire ◄──┼──────────┘ (PWR GND) │
│ │ │
│ RED wire ◄──┐ │(Motor Power +12V) │
└──────────────┼─┼───────────────────────┘
│ │
┌────────────────────┐ │ │
│ 12V Power Supply │ │ │
│ │ │ │
│ +12V ─────────────┼─┘ │
│ GND ──────────────┼───┘ (Common Ground)
└────────────────────┘
```
## Connection Summary
| TEENSY Pin | BLDC Motor Wire | Function |
|------------|----------------|----------|
| Pin 2 | WHITE wire | PWM Speed Control (0-5V) |
| Pin 3 | BLUE wire | Direction (Float/GND) |
| Pin 4 | YELLOW wire | FG Feedback (speed sensor) |
| GND | BLACK wire (logic) | Common Ground |
| - | RED wire | Motor Power (+12V) |
| - | BLACK wire (power) | Motor Power Ground |
## Important Notes
- Ensure common ground between Teensy and 12V power supply
- **PWM wire (WHITE)**: 0-5V PWM signal controls motor speed
- **Direction wire (BLUE)**: Float = one direction, GND = opposite direction
- **FG wire (YELLOW)**: Outputs speed feedback pulses for RPM monitoring
- **Motor power (RED/BLACK)**: Separate high-current power lines for the motor
## Usage
1. Upload the code to your Teensy 4.x
2. Open Serial Monitor at 9600 baud
3. When prompted, enter a 3-digit PWM value (0-255) to set motor speed
4. Motor will run in one direction, then reverse
## Features
- PWM speed control with 10kHz frequency
- Bidirectional motor control
- Real-time speed feedback monitoring via FG pin
- Frequency-to-duty cycle mapping for closed-loop control
- Serial interface for speed input and monitoring
## Hardware
- **Motor**: B2418 Mini 310 BLDC Brushless Motor with built-in driver
- **Microcontroller**: Teensy 4.x
- **Power Supply**: 12V DC
Attachments
Last edited:

