0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

s3003をNucleo-F446REで動かす

Last updated at Posted at 2021-05-30

#s3003をNucleo-F446REで動かす
download.jpg

##使用道具
s3003サーボモータ
stm32 Nucleo-F446RE

##開発環境
STM32 CubeIDE 

##PIN設定
2021-05-30 (3).png

今回はTIM3_CH1を使ってみる

##クロックの設定
2021-05-30 (5)_LI.jpg

8MHzのクリスタルを使って16MHzを出力

2021-05-30 (2).png

50Hzの周期にしたいと考えているので
16Mz/50Hz = 320 * 1000 = prescaler * counter period

##プログラム
/* Private function prototypes -----------------------------------------------/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_TIM3_Init(void);
/
USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------/
/
USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**

  • @brief The application entry point.
  • @retval int
    /
    int main(void)
    {
    /
    USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */
SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals /
MX_GPIO_Init();
MX_TIM3_Init();
/
USER CODE BEGIN 2 /
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
/
USER CODE END 2 */

/* Infinite loop /
/
USER CODE BEGIN WHILE /
while (1)
{
/
USER CODE END WHILE */
__HAL_TIM_SET_COMPARE(&htim3,TIM_CHANNEL_1,25);
HAL_Delay(2000);
__HAL_TIM_SET_COMPARE(&htim3,TIM_CHANNEL_1,150);
HAL_Delay(2000);

}
}

サーボが0.5~3msの制御パルスなので
50Hz * 0.5 = 25
50Hz * 3 = 150

で-60から+60°まで動くよ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?