No ACL setup yet! Denying access to everyone.
en:edu:zmitac:s2:aih:lab:stm32fan

This is an old revision of the document!


Fan and Servo controlling

Both the fan and servo are controlled with a PWM signal. In the STM32WB55 microcontroller, there are two timers capable of generating PWM signals. One of them is connected to the RGB LED, second is connected to the fan and servo.

Tab. 1: Assignment of pins for the fan and servo
GPIO noelement
PA0 Servo
PA1 Fan

In the stm32duino examples 1), there is a simple program which allows us to control a single LED with PWM. It is named “All-in-one_setPWM” 2). It uses hardware timer output connected directly to an LED. We will modify this example to control the fan and servo. The code is composed of two files FanSrvTest.h and FanSrvTest.cpp. The *.h file defines pins for the fan and servo, declares variables for timer, channels and

#include "Arduino.h"

#ifndef _SRV_TestLib
#define _SRV_TestLib

// PWM timer 2 for Servo and Fan control
#define SERVO_PWM_PIN PA0
#define FAN_PWM_PIN PA1

// PWM variables definitions
TIM_TypeDef *SRVInstance;        //General hardware instance
uint32_t channelSRV, channelFAN; //2 channels
HardwareTimer *MyTimServo;       //Hardware Timer class for Fan and Servo PWM

//Prototypes of funcions
void FanSrvSetup();
void fFanSet(int pPercent);      //Change the fan speed (0-100)
void fSrvSet(int pAngle);        //Change the servo angle (0-180)

#endif
en/edu/zmitac/s2/aih/lab/stm32fan.1705171770.txt.gz · Last modified: by ktokarz