1209 views|7 replies

1453

Posts

1

Resources
The OP
 

[Xiaohua HC32F448 Review] + Stepper Motor Drive Control [Copy link]

 This post was last edited by jinglixixi on 2023-8-13 10:55

The HC32F448 development board can be used to drive the stepper motor. The stepper motor model selected here is 28BYJ-48. Since its working current is relatively large, it needs to be equipped with a corresponding driver module. Its driver chip is ULN2003, and the pin arrangement of the chip is shown in Figure 1.

Figure 1 Pinout

The driver chip ULN2003 consists of 7 groups of Darlington circuits, each of which is connected in series with a 2.7K base resistor. Under the working voltage of 5V, it can be directly connected to TTL and CMOS circuits, and can directly process data that originally required standard logic buffers to process.

ULN2003 has high operating voltage, large operating current, sink current up to 500mA, and can withstand a voltage of 50V in the off state.

28BYJ-48 is a 4-phase 5-wire reduction stepper motor, it has 5 leads, VCC is connected to the center tap wire of the motor (usually red), and the other 4 are connected to the motor's A, B, C, and D phases. The motor has a diameter of 28mm, voltage: 5V, step angle: 5.625 x 1/64, and reduction ratio: 1/64.

Figure 2 Internal type and signal driving sequence

To control the rotation of the stepper motor, the pin connection relationship between it and the development board is as follows:

MA:PC7

MB:PE14

MC:PE12

MD:PC4

To output high and low levels, the pins are defined as:

#define MAH GPIO_SetPins(GPIO_PORT_C, GPIO_PIN_07)

#define MAL GPIO_ResetPins(GPIO_PORT_C, GPIO_PIN_07)

#define MBH GPIO_SetPins(GPIO_PORT_E, GPIO_PIN_14)

#define MBL GPIO_ResetPins(GPIO_PORT_E, GPIO_PIN_14)

#define MCH GPIO_SetPins(GPIO_PORT_E, GPIO_PIN_12)

#define MCL GPIO_ResetPins(GPIO_PORT_E, GPIO_PIN_12)

#define MDH GPIO_SetPins(GPIO_PORT_C, GPIO_PIN_04)

#define MDL GPIO_ResetPins(GPIO_PORT_C, GPIO_PIN_04)

The configuration function for the used pins is:

void Init_BJDJ(void)
{
    stc_gpio_init_t stcGpioInit;
    (void)GPIO_StructInit(&stcGpioInit);
    stcGpioInit.u16PinState = PIN_STAT_RST;
    stcGpioInit.u16PinDir = PIN_DIR_OUT;
	(void)GPIO_Init(GPIO_PORT_C, GPIO_PIN_04, &stcGpioInit);
	(void)GPIO_Init(GPIO_PORT_C, GPIO_PIN_07, &stcGpioInit);
	(void)GPIO_Init(GPIO_PORT_E, GPIO_PIN_12, &stcGpioInit);
	(void)GPIO_Init(GPIO_PORT_E, GPIO_PIN_14, &stcGpioInit);
}

The main program for testing the forward and reverse rotation of the stepper motor is:

int32_t main(void)
{
	unsigned int X,Y;
    LL_PERIPH_WE(LL_PERIPH_GPIO);
    LED_Init();
    Init_BJDJ();
	LL_PERIPH_WP(LL_PERIPH_GPIO);
	DDL_DelayMS(100);
	MAL;
    MBL;
    MCL;
    MDL;
    // 转动
    for(X=0;X<192;X++)
    {
      for(Y=0;Y<8;Y++)
      {
         MDL;
         MAH; //A
         delay (n);
         MBH; //AB
         delay (n);
         MAL; //B
         delay (n);
         MCH; //BC
         delay (n);
         MBL; //C
         delay (n);
         MDH; //CD
         delay (n);
         MCL; //D
         delay (n);
         MAH; //DA
         delay (n);
       }
    }
    DDL_DelayMS(100);
    // 换向
    for(X=0;X<192;X++)
    {
      for(Y=0;Y<8;Y++)
      {
         MDH;
         MAH; //DA
         delay (n);
         MAL; //D
         delay (n);
         MCH; //CD
         delay (n);
         MDL; //C
         delay (n);
         MBH; //BC
         delay (n);
         MCL; //B
         delay (n);
         MAH; //AB
         delay (n);
         MBL; //A
         delay (n);
       }
    }
    // 停止
	MAL;
    MBL;
    MCL;
    MDL;
    for (;;) {
        LED_G_TOGGLE();
		DDL_DelayMS(DLY_MS);
    }
}

After the program is compiled and downloaded, its running effects are shown in Figures 3 to 5.

Figure 1 Rotation state 1

Figure 2 Rotation state 2

Figure 3 Rotation state 3

When in use, the speed can also be changed by adjusting the delay value.

In addition, when using the buttons on the development board, the direction of the motor can be controlled in real time by pressing the buttons.

Video Demonstration:

This post is from Domestic Chip Exchange

Latest reply

Teacher Li's lecture was very good! The students were very educated. They just started to learn about stepper motors.  Details Published on 2023-9-3 09:25
 
 

6822

Posts

11

Resources
2
 
A detailed explanation of how to control a stepper motor. Teacher Li’s posts are always excellent!
This post is from Domestic Chip Exchange
 
 
 

1462

Posts

0

Resources
3
 
Are there any very thin stepper motors with a thickness of about 10mm and a shaft diameter of about 1mm? I searched online for a long time and found that they were very thick, about 20mm.
This post is from Domestic Chip Exchange
 
 
 

1453

Posts

1

Resources
4
 
lugl4313820 posted on 2023-8-13 17:14 A detailed explanation of how to control a stepper motor. Teacher Li’s posts are always so excellent!

Thank you for the award, and for your support!!!

This post is from Domestic Chip Exchange
 
 
 

1453

Posts

1

Resources
5
 
This post was last edited by jinglixixi on 2023-8-14 00:51
lkh747566933 posted on 2023-8-13 18:59 Is there a very thin stepper motor with a thickness of about 10mm and a shaft diameter of about 1mm? I searched online for a long time and found that it was very thick, about 20mm.

See if this is available?

https://item.taobao.com/item.htm?spm=a230r.1.14.16.275331270BSAkx&id=711000438484&ns=1&abbucket=15#detail

This post is from Domestic Chip Exchange
 
 
 

1462

Posts

0

Resources
6
 
jinglixixi posted on 2023-8-14 00:50 See if this is available? https://item.taobao.com/item.htm?spm=a230r.1.14.16.275331270BSAkx&id=71100 ...

Well, thanks for the link, the size is OK, I bought one and tried it. My original one had 5 wires, this one has 4 wires, I will come back and see how to modify the circuit

This post is from Domestic Chip Exchange
 
 
 

1453

Posts

1

Resources
7
 
lkh747566933 posted on 2023-8-15 15:05 Well, thanks for the link you found. The size is OK. I bought one and came back to try it. The one I originally had was 5-wire, and this one has 4-wire. I'll come back and take a look...

OK, you can also ask the merchant if they can provide some relevant information, which will be more convenient.

This post is from Domestic Chip Exchange
 
 
 

3

Posts

0

Resources
8
 

Teacher Li's lecture was very good! The students were very educated. They just started to learn about stepper motors.


This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list