3320 views|5 replies

143

Posts

0

Resources
The OP
 

[AutoChips AC7801x motor demo board review] + Different PWM configurations for motor control [Copy link]

 This post was last edited by Xianjing on 2020-11-12 22:41

Preface: Those who work on motor control know that advanced timers are the essence of motor control, including complementary PWM, PWM with dead zone output, and shift PWM... Currently, AC7801 includes these functions, which is really powerful, and it is really the rhythm of the rise of domestic MCU. I don’t know if the price is beautiful. If it is beautiful, it will be amazing. However, that... we don’t care, we care about different PWM configurations.

Features and Structure: Each PWM channel uses one input/output (I/O) pin, CHn (PWM channel (n)), where n is the channel number (0-7). The core of the PWM is a 16-bit counter with programmable initial and final values, and its count can be up or up-down. The
following figure is a PWM structure diagram.

There are several key registers here:

Initialization Register (PWM_INIT)

Configure the clock, configure the divider, count mode, and overflow interrupt.

Counter Register (PWM_CNT)
15: Bit 0: The CNT register contains the PWM counter value. Reset clears the CNT register. Writing any value to COUNT updates the counter with its initial value CNTIN.

Maximum Count Value Register (PWM_MCVR)
15:0 Bit: The MCVR register contains the modulo value of the PWM counter. When the PWM count value reaches the MCVR value, the overflow flag (CNTOF) is set at the next clock and the next value of the counter depends on the selected counting method. Writing to the MCVR register latches the value into the buffer. Depending on the register updated from the write buffer, the MCVR register is updated with the value of its write buffer. Before writing to the MCVR register, initialize the PWM counter by writing to CNT.

Channel Value Registers (PWM_CHnV)
15:0 bits: These registers contain the captured PWM counter value for input mode or the match value for output mode. In input capture, capture test, and dual edge capture modes, any write operation to the CHnV register is ignored. In output mode, writing to the CHnV register latches the value in the buffer. Based on the register updated from the write buffer, the CHnV register is updated with the value of its write buffer.

…………

There are many more registers that need to be sorted out. Please go and have a look. Here is a brief explanation.

Up-counting combination mode:
period = (MCVR-CNTIN+1)*PWM counter clock period, duty cycle = |CH(n+1)V-CH(n)V|*PWM counter clock period
Up-down counting combination mode:
period = 2*(MCVR-CNTIN)*PWM counter clock period, duty cycle = 2*(|CH(n+1)V-CH(n)V|)*PWM counter clock period

Next, we need to configure P0_CH2 (PB11) and P0_CH3 (PB12) in the above figure.

Complementary output: 1. Upper and lower channels, high effective

combineChConfig[0].pairChannel = PWM_CH_2; //PWM通道对数,PWM_CH_0/2/4/6对应PAIR0/1/2/3
combineChConfig[0].ch1stValue = MOD_PWM >> 2;; //通道2n channel值,n为PWM对数编号
combineChConfig[0].ch2ndValue = MOD_PWM >> 1;; //通道2n+1 channel值,n为PWM对数编号
#if 1
combineChConfig[0].levelMode = PWM_HIGH_TRUE; //输出PWM高有效,如果占空比设为25%,是指的高有效电平占比25%
#endif
combineChConfig[0].deadtimeEn = DISABLE;//死区插入去能
combineChConfig[0].complementEn = ENABLE;//互补模式使能,使能后,PWM通道波形互补,DISABLE波形输出同向
combineChConfig[0].ch1stMatchDir = PWM_MATCH_DIR_DOWN;//仅在向上-向下计数(countMode为PWM_UP_DOWN_COUNT)组合模式有效,用于选择匹配生效点方向
combineChConfig[0].ch2ndMatchDir = PWM_MATCH_DIR_DOWN;//仅在向上-向下计数(countMode为PWM_UP_DOWN_COUNT)组合模式有效,用于选择匹配生效点方向
combineChConfig[0].ch1stPolarity = PWM_OUTPUT_POLARITY_ACTIVE_HIGH;//输出极性高有效,PWM mask后PWM输出低电平
combineChConfig[0].ch2ndPolarity = PWM_OUTPUT_POLARITY_ACTIVE_HIGH;//输出极性高有效,PWM mask后PWM输出低电平

The waveform of this PWM mode configuration is as follows

2. Up and down channels, low effective

combineChConfig[0].pairChannel = PWM_CH_2; //PWM通道对数,PWM_CH_0/2/4/6对应PAIR0/1/2/3
combineChConfig[0].ch1stValue = MOD_PWM >> 2;; //通道2n channel值,n为PWM对数编号
combineChConfig[0].ch2ndValue = MOD_PWM >> 1;; //通道2n+1 channel值,n为PWM对数编号
#if 1
combineChConfig[0].levelMode = PWM_LOW_TRUE; //输出PWM低有效,如果占空比设为25%,是指的低有效电平占比25%
#endif
combineChConfig[0].deadtimeEn = DISABLE;//死区插入去能
combineChConfig[0].complementEn = ENABLE;//互补模式使能,使能后,PWM通道波形互补,DISABLE波形输出同向
combineChConfig[0].ch1stMatchDir = PWM_MATCH_DIR_DOWN;//仅在向上-向下计数(countMode为PWM_UP_DOWN_COUNT)组合模式有效,用于选择匹配生效点方向
combineChConfig[0].ch2ndMatchDir = PWM_MATCH_DIR_DOWN;//仅在向上-向下计数(countMode为PWM_UP_DOWN_COUNT)组合模式有效,用于选择匹配生效点方向
combineChConfig[0].ch1stPolarity = PWM_OUTPUT_POLARITY_ACTIVE_HIGH;//输出极性高有效,PWM mask后PWM输出低电平
combineChConfig[0].ch2ndPolarity = PWM_OUTPUT_POLARITY_ACTIVE_HIGH;//输出极性高有效,PWM mask后PWM输出低电平

The waveform of this PWM mode configuration is as follows

Non-complementary mode: 3, upper and lower channels, high effective (same direction output)

combineChConfig[0].pairChannel = PWM_CH_2; //PWM通道对数,PWM_CH_0/2/4/6对应PAIR0/1/2/3
combineChConfig[0].ch1stValue = MOD_PWM >> 2;; //通道2n channel值,n为PWM对数编号
combineChConfig[0].ch2ndValue = MOD_PWM >> 1;; //通道2n+1 channel值,n为PWM对数编号
#if 1
combineChConfig[0].levelMode = PWM_HIGH_TRUE; //输出PWM高有效,如果占空比设为25%,是指的高有效电平占比25%
#endif
combineChConfig[0].deadtimeEn = DISABLE;//死区插入去能
combineChConfig[0].complementEn = DISABLE;//互补模式去使能,DISABLE波形输出同向
combineChConfig[0].ch1stMatchDir = PWM_MATCH_DIR_DOWN;//仅在向上-向下计数(countMode为PWM_UP_DOWN_COUNT)组合模式有效,用于选择匹配生效点方向
combineChConfig[0].ch2ndMatchDir = PWM_MATCH_DIR_DOWN;//仅在向上-向下计数(countMode为PWM_UP_DOWN_COUNT)组合模式有效,用于选择匹配生效点方向
combineChConfig[0].ch1stPolarity = PWM_OUTPUT_POLARITY_ACTIVE_HIGH;//输出极性高有效,PWM mask后PWM输出低电平
combineChConfig[0].ch2ndPolarity = PWM_OUTPUT_POLARITY_ACTIVE_HIGH;//输出极性高有效,PWM mask后PWM输出低电平

The waveform of this PWM mode configuration is as follows

4. Up and down channels, low effective (same direction output)

combineChConfig[0].pairChannel = PWM_CH_2; //PWM通道对数,PWM_CH_0/2/4/6对应PAIR0/1/2/3
combineChConfig[0].ch1stValue = MOD_PWM >> 2;; //通道2n channel值,n为PWM对数编号
combineChConfig[0].ch2ndValue = MOD_PWM >> 1;; //通道2n+1 channel值,n为PWM对数编号
#if 1
combineChConfig[0].levelMode = PWM_LOW_TRUE; //输出PWM低有效,如果占空比设为25%,是指的低有效电平占比25%
#endif
combineChConfig[0].deadtimeEn = DISABLE;//死区插入去能
combineChConfig[0].complementEn = DISABLE;//互补模式去使能,DISABLE波形输出同向
combineChConfig[0].ch1stMatchDir = PWM_MATCH_DIR_DOWN;//仅在向上-向下计数(countMode为PWM_UP_DOWN_COUNT)组合模式有效,用于选择匹配生效点方向
combineChConfig[0].ch2ndMatchDir = PWM_MATCH_DIR_DOWN;//仅在向上-向下计数(countMode为PWM_UP_DOWN_COUNT)组合模式有效,用于选择匹配生效点方向
combineChConfig[0].ch1stPolarity = PWM_OUTPUT_POLARITY_ACTIVE_HIGH;//输出极性高有效,PWM mask后PWM输出低电平
combineChConfig[0].ch2ndPolarity = PWM_OUTPUT_POLARITY_ACTIVE_HIGH;//输出极性高有效,PWM mask后PWM输出低电平

The waveform of this PWM mode configuration is as follows

Four modes are written. Which mode should you use? It depends on your own project and your own pre-driver selection.

Finally, attach the project code PWM.zip (2.11 MB, downloads: 23)

The next chapter will be even more exciting!!!

This post is from Domestic Chip Exchange

Latest reply

Come on, thanks for sharing!   Details Published on 2020-11-12 22:31
 
 

143

Posts

0

Resources
2
 

sofa

This post is from Domestic Chip Exchange
 
 
 

1942

Posts

2

Resources
3
 

Sure, you can use an oscilloscope. Is this the one you bought at home?

This post is from Domestic Chip Exchange

Comments

No money, use the company's  Details Published on 2020-11-13 08:55
 
 
 

7462

Posts

2

Resources
4
 

Come on, thanks for sharing!

This post is from Domestic Chip Exchange

Comments

Please stay tuned  Details Published on 2020-11-13 08:55
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

143

Posts

0

Resources
5
 
w494143467 posted on 2020-11-12 22:00 Sure, the oscilloscope is used. Did you buy the oscilloscope at home?

No money, use the company's

This post is from Domestic Chip Exchange
 
 
 

143

Posts

0

Resources
6
 
freebsder posted on 2020-11-12 22:31 Come on, thank you for sharing!

Please stay tuned

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