發表文章

目前顯示的是 2月, 2021的文章

Programming The Robot Car

圖片
    When connecting the USB2TTL to the control board, NEVER USE THE 5 VOLT LINE . It will burn the microcontroller. You must not power up the control board (inserting USB2TTL to PC will power up the 3.3 volt line) unless all connections are properly established. That is, connect the USB2TTL to the control board first.  Connect the USB2TTL to PC afterward. Blink the LEDs There are three controllable LEDs. A blue LED comes with the MCU module. The control board bears a green LED and a yellow LED. The first program to write is to blink the LEDs in the background and control them in the main() function. /* main.cpp */ oi ai u i e i ; a ou o a e ei e i e ou i u io e u e a e O O O A A O }; e u e o o UE EE E O }; oi e e o o e a e ; i ai oi e UE O ; ai ; ai o 1 e o u i a i e e EE O ; ai ; a ou o a e e

PID Speed Control

圖片
    In this post, all codes are NOT tested. the PIDs are not tuned yet. Derived wheel rotation speed from Wheel Count Have you ever calibrated the wheel counter? Let me give you some data. 1. one revolution = 60 counts 2. wheel diameter = 56 mm 3. sampling time = 2.5 ms What do you think about the MAXIMUM change in count per 2.5 ms? Doing a simple arithmetic, you will learn that it is not likely to exceed 15 counts per 2.5 ms. In fact, 1 count per 2.5 ms is equivalent to 1.17 m/s. So 2.5 ms is not suitable for deriving the car speed. 20 ms will give a lowest controllable speed of 15 cm/s. My plan to obtain a speed would be: 1. get the change in count every 2.5 ms and save it for at least 8 cycles. 2. sum up 8 consecutive readings every 2.5 ms to obtain speed as counts per 20 ms. I will use 1 integer to hold 8 samples. Recall that each sample's value would not exceed 15, so 4 bits is enough. Integer is 32 bits long  (stm32f103 is 32-bit MCU), so it can hold 8 samples. The r

Labelling Your Robot Car

圖片
  Please enter your student ID EIE3105 21234567D EIE3105 EIE3106 Student ID: Print this page and cut out the label. The width of the label is around 5 cm. You may need to scale your printout. Use glue or otherwise, stick it onto the car as shown. Please do not cover the label with transparent tape or any protective coating.

PlatformIO

圖片
   A student wanted to use PlatformIO for coding. I have heard of it for a while and would like to give it a try. It has an advantage of covering many platforms: stm32, avr, pic32. It provides all the tools (compiler and uploader) in a single installation. And it is rich in editing features. It also provides a number of popular frameworks such as arduino (I don't like it but its really good for high school students and hobbyist). I just tested it for our black pill board. It works! There is only one difference. It changes the stm32 header file to stm32f1xx.h. Whereas keil uses stm32f10x.h AVR - non arduino System Clock Setting on STM32F103 Project The default setting in PlatformIO is found to be 8 MHz for APB2. The setting in Keil is 72 MHz for APB2 and 36 MHz for APB1. The following code will boost up the frequencies. RCC->CFGR = RCC_CFGR_PLLMULL9 | RCC_CFGR_PLLSRC | RCC_CFGR_PPRE1_DIV2; RCC->CR |= RCC_CR_HSEON; while (!(RCC->CR & RCC_CR_HSERDY)); R