When the frequency is 10K, the duty cycle can achieve a change accuracy of 1%, while when it is 100K, the change accuracy can only be 10%.
#define PWM_CLK1M_ARR_10K 100-1
void IzADCPWMInit(uint8_t duty)//10%~90%
{
if(duty>90)
{
duty = 90;
}
if(duty<10)
{
duty = 10;
}
//reset
/* TIM4 enable counter */
TIM_Cmd(TIM4, DISABLE);
/* TIM4 Main Output Enable */
TIM_CtrlPWMOutputs(TIM4, DISABLE);
//end of reset
/* System Clocks Configuration */
RCCPWMADCConfiguration();
/* GPIO Configuration */
GPIOPWMADCConfiguration();
/*------------------------------------------------ -----------------------
TIM3 Configuration: generate 4 PWM signals with 4 different duty cycles:
The TIM3CLK frequency is set to SystemCoreClock (Hz), to get TIM3 counter
clock at 24 MHz the Prescaler is computed as following:
- Prescaler = (TIM3CLK / TIM3 counter clock) - 1
SystemCoreClock is set to 72 MHz for Low-density, Medium-density, High-density
and Connectivity line devices and to 24 MHz for Low-Density Value line and
Medium-Density Value line devices
The TIM3 is running at 36 KHz: TIM3 Frequency = TIM3 counter clock/(ARR + 1)
= 24 MHz / 666 = 36 KHz
TIM3 Channel1 duty cycle = (TIM3_CCR1/ TIM3_ARR)* 100 = 50%
TIM3 Channel2 duty cycle = (TIM3_CCR2/ TIM3_ARR)* 100 = 37.5%
TIM3 Channel3 duty cycle = (TIM3_CCR3/ TIM3_ARR)* 100 = 25%
TIM3 Channel4 duty cycle = (TIM3_CCR4/ TIM3_ARR)* 100 = 12.5%
-------------------------------------------------- -------------------------- */
/* Compute the prescaler value */
//PrescalerValue = (uint16_t) (SystemCoreClock / 24000000) - 1;//24M
//TIM3 Frequency=1MHz/(9999+1) =100Hz
PrescalerValue = (uint16_t) (SystemCoreClock / 1000000) - 1; //TIM3 counter clock: 1MHz
/* Time base configuration */
//TIM_TimeBaseStructure.TIM_Period = 665;//(ARR)
//TIM3 Frequency=1MHz/(9999+1) =100Hz
//TIM_TimeBaseStructure.TIM_Period = 10000-1; //TIM3 counter clock/TIM3 Frequency
//TIM3 Frequency=1MHz/(99+1) =10 000Hz
TIM_TimeBaseStructure.TIM_Period = PWM_CLK1M_ARR_10K;//PWM_CLK1M_ARR_100; //TIM3 counter clock/TIM3 Frequency
TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
/* PWM1 Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
//CCR1_Val =TIM3_ARR*duty/100;
//TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
// TIM_OCInitStructure.TIM_Pulse = (uint16_t)(10000-1)*duty/100;
TIM_OCInitStructure.TIM_Pulse = (uint16_t)(PWM_CLK1M_ARR_10K)*duty/100;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
// TIM_OC1Init(TIM3, &TIM_OCInitStructure);
// TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
//PB6: TM4 Channel1
TIM_OC1Init(TIM4, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);
//PB8: TM4 Channel3
/* PWM1 Mode configuration: Channel3 */
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = (uint16_t)(PWM_CLK1M_ARR_10K)*duty/100;
TIM_OC3Init(TIM4, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);
//PB7: TM4 Channel2
/* PWM1 Mode configuration: Channel2 */
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = (uint16_t)(PWM_CLK1M_ARR_10K)*duty/100; ;
TIM_OC2Init(TIM4, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);
#if 0
/* PWM1 Mode configuration: Channel4 */
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR4_Val;
TIM_OC4Init(TIM3, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable);
#endif
TIM_ARRPreloadConfig(TIM4, ENABLE);
/* TIM4 enable counter */
TIM_Cmd(TIM4, ENABLE);
/* TIM4 Main Output Enable */
TIM_CtrlPWMOutputs(TIM4, ENABLE);
}
Previous article:Summary of STM32's CAN1 module
Next article:The difference between RO segment, RW segment and ZI segment in ARM
Recommended ReadingLatest update time:2024-11-16 15:48
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
- Intelligent Control Technology of Permanent Magnet Synchronous Motor (Written by Wang Jun)
- usb_host_device_code
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Introduction to bq24780S, commonly used for laptop battery management
- Which is more flexible, a human or a robot? Shadow’s dexterous hands stack cups
- Answer the question and win a prize: Mentor Tessent Automotive-related test solutions
- They are both AR HUDs, why is DLP better?
- Reset mode of TMS320C6678
- msp430F4152 official website routine program
- How to use type B leakage current sensor in charging gun IC-CPD, charging pile
- Can someone tell me what the built-in heating function of the sht3x series does?
- Leverage the advantages of real-time operating systems with MSP432 MCUs
- Start with TF card made by card reader