3508 views|6 replies

6818

Posts

11

Resources
The OP
 

【Qinheng RISC-V core CH582】Timer PWM drive servo [Copy link]

 

[Qinheng RISC-V core CH582] Feasibility of using solid-state relays to control the heating tube of the heater in CH582 https://en.eeworld.com/bbs/thread-1197474-1-1.html

My review work is to DIY a mobile phone APP to control the electric heater. The main idea is to modify an electric heater in my home. The original heater is a heating wire, and the fan blows out hot air after electric heating, similar to the principle of a hair dryer. Now the idea of modification is to replace the manual heating switch with a solid-state relay, and use a servo to control the fan potentiometer.

We have used the APP to control the switch before. Now we are going to use the APP to control the servo to control the fan potentiometer:

1. Add 3 buttons under the original APP to control the servo to the specified angle, and add related functions for sending instructions on the WeChat applet.

2. The servo I use is the one I bought N years ago: ES06MA, and it seems that the maximum turning angle is only 180.

1. Check the data. The rotation angle of the servo is determined by a 20ms (50Hz) period PWM waveform to control the motor rotation angle. To get 50Hz PWM, you need to use timer PWM.

2. Looking through the routines\CH583EVT\EVT\EXAM\TMR, I decided to use TMR3:

#if 1 /* 定时器3,PWM输出 */

    GPIOB_ResetBits(GPIO_Pin_22); // 配置PWM口 PB22
    GPIOB_ModeCfg(GPIO_Pin_22, GPIO_ModeOut_PP_20mA);

    TMR3_PWMInit(High_Level, PWM_Times_1);
    TMR3_PWMCycleCfg(1200000); // 周期 50Hz 20ms  具体为:60 000 000 /1 200 000 = 50
    TMR3_Disable();
    TMR3_PWMActDataWidth(600000); // 占空比 50%, 修改占空比必须暂时关闭定时器
    TMR3_Enable();

#endif

After configuration, use an oscilloscope to measure PB22 and get a 50Hz waveform:

Rewrite simpleProfileChangeCB receiving callback function

static void simpleProfileChangeCB(uint8_t paramID, uint8_t *pValue, uint16_t len)
{
    switch(paramID)
    {
        case SIMPLEPROFILE_CHAR1:
        {
            uint8_t newValue[SIMPLEPROFILE_CHAR1_LEN];
            tmos_memcpy(newValue, pValue, len);
            PRINT("profile ChangeCB CHAR1.. %s\n",newValue);
            if(pValue[0] == '0')
            {
                GPIOB_SetBits(GPIO_Pin_19);
            }
            else if (pValue[0] == '1') {
                GPIOB_ResetBits(GPIO_Pin_19);
            }
            else if (pValue[0] == 'a') //97 'a'
            {
                TMR3_Disable();
                TMR3_PWMActDataWidth(32000); // 0度 0.5ms
                TMR3_Enable();
            }
            else if (pValue[0] == 'b') {
                TMR3_Disable();
                TMR3_PWMActDataWidth(96000);// 1.5ms = 60,000 *1.5
                TMR3_Enable();
            }
            else if (pValue[0] == 'c'){
                TMR3_Disable();
                TMR3_PWMActDataWidth(128000); // 180 2ms 120*1000
                TMR3_Enable();
            }
            break;
        }

After downloading the program, you can control the rotation of the servo.


So far, the basic parts of the heater have been debugged, and the next step is assembly and evaluation.

This post is from Domestic Chip Exchange

Latest reply

This post was last edited by lyj33 on 2022-7-15 10:34 lugl4313820 posted on 2022-7-14 20:35 If your waveform does not change, it will stay there. It will only turn when the waveform changes. If you have time, go and look at the driving principle of the servo. How to control multiple servos?   Details Published on 2022-7-15 09:01
 
 

5213

Posts

239

Resources
2
 

While evaluating, I also upgraded the daily necessities

This post is from Domestic Chip Exchange
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
 
 
 

2w

Posts

74

Resources
3
 

Looking forward to the finished product :)

This post is from Domestic Chip Exchange
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
Personal signature

加油!在电子行业默默贡献自己的力量!:)

 
 
 

2

Posts

0

Resources
4
 

I wrote it like this, why after the program is burned in, the servo is initialized to rotate once?

#if 1 /* Timer 3, PWM output */

GPIOB_ResetBits(GPIO_Pin_22); // Configure PWM port PB22
GPIOB_ModeCfg(GPIO_Pin_22, GPIO_ModeOut_PP_20mA);

TMR3_PWMInit(High_Level, PWM_Times_1);
TMR3_PWMCycleCfg(1200000); // Cycle 50Hz 20ms, details are 60 000 000/1 200 000=50
TMR3_Disable();
TMR3_PWMActDataWidth(600000); // Duty cycle 50%, to modify the duty cycle must temporarily turn off the timer
TMR3_Enable();

TMR3_Disable();
TMR3_PWMCycleCfg(32000);
TMR3_Enable();

This post is from Domestic Chip Exchange

Comments

If your waveform does not change, it will stay there. It will only rotate if the waveform changes. If you have time, go and look up the driving principle of the servo.  Details Published on 2022-7-14 20:35
 
 
 

6818

Posts

11

Resources
5
 
lyj33 posted on 2022-7-14 17:02 I wrote it like this, why does the servo only rotate once after the program is burned in? #if 1 /* Timer 3, PWM output*/ ...

If your waveform does not change, it will stay there. It will only rotate if the waveform changes. If you have time, go and look up the driving principle of the servo.

This post is from Domestic Chip Exchange
 
 
 

2

Posts

0

Resources
6
 
This post was last edited by lyj33 on 2022-7-15 10:34
lugl4313820 posted on 2022-7-14 20:35 If your waveform does not change, it will stay there. It will only turn when the waveform changes. If you have time, go and look at the driving principle of the servo.

How to control multiple servos?

This post is from Domestic Chip Exchange

Comments

One IO can control one channel, the principle is the same.  Details Published on 2022-7-15 12:50
 
 
 

6818

Posts

11

Resources
7
 
lyj33 posted on 2022-7-15 09:01 lugl4313820 posted on 2022-7-14 20:35 If your waveform does not change, it will stay there. Only when the waveform changes will it turn. There is...

One IO can control one channel, the principle is the same.

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