There are five 16-bit timers in S3C2440, timer0, timer1, timer2, timer3 and timer4. Among them, only timer4 is an internal timer without output pins. Therefore, only timers 0, 1, 2, and 3 have pulse width modulation (PWM) function. Timer 0 has a dead zone generator for high current devices. (Hereinafter, timer 0 is used as an example)
The PWM output of S3C2440 mainly uses the comparison register TCMPB0 (0x51000010).
When the timer is enabled, the timer count buffer register (TCNTBn) gets an initial value that is loaded into the down counter. The timer compare buffer register (TCMPBn) has an initial value that is loaded into the comparator for comparison with the down counter value.
Each timer has its own 16-bit down counter driven by the timer clock. When the down counter reaches zero, a timer interrupt request is generated to notify the CPU that the timer operation has been completed. When the timer counter reaches 0, the corresponding TCNTBn value is also loaded into the down counter to continue the next operation (auto-load). However, if the timer is stopped, for example by clearing the timer enable bit of TCONn in timer run mode, the value of TCNTBn is not loaded into the counter.
The value of TCMPBn is used for pulse width modulation. When the value of the down counter matches the value of the compare register in the timer control logic, the timer control logic changes the output level. Therefore, the compare register determines the on time of the PWM output.
With the above knowledge, we can know
When initializing the timer, the following registers need to be set (taking timer 0 as an example):
Timer output clock frequency = PCLK/(prescaler value + 1)/(divider value)
TCFG0 (0x51000000), such as: TCFG0 = 99; // prescaler value = "99"
TCFG1(0x51000004), such as: TCFG1=0x03;//divider value="1/16"
Thus, when PCLK=400M, the timer output frequency is 6.25M
Next, we need to set the initial value for the timer.
TCNTB0 (0x5100000c), for example, TCNTB0 = 62500; // load the initial value and interrupt once every 1s
TCMPB0 (0x51000010), for example, TCMPB0 = rTCNTB0>>1; // 50%
If PWM is not used, TCMPB0 can be left unset or set to 0.
Then you can start the timer, but you must manually load TCON=1<<1 for the first time;
After loading, change to automatic loading and start timer TCON=0x09;
Where TCON (0x51000008)
In order to drive the buzzer, the I/O port must be initialized.
The board I used was Friendly, and the buzzer was connected to GPB0.
Enable PWM by changing the last two bits of GPBCON (0x56000010)
void GPIO_init(void)
{
rGPBCON &= ~3;
rGPBCON |= 2;
}
Previous article:Friendly Arm Mini2440NORflash bootloader programming details --- personally tested and available
Next article:A brief introduction to the FriendlyArm mini2440
Recommended ReadingLatest update time:2024-11-23 10:16
- Popular Resources
- Popular amplifiers
- Example interpretation of 51 single chip microcomputer complete learning and application
- Practice of Serial Communication between Single Chip Microcomputer and Computer (Zhang Xiuguan)
- Example interpretation of 51 single chip microcomputer complete learning and application
- Integrated wireless transceiver & 8-bit RISC (reduced instruction set) MCU SOC chip Ci2451
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Super cool! ! The host computer is combined with the Bluetooth phone protocol stack to realize PC control of mobile phones
- Application of Active and Passive Safety Technology in Automobiles in the New Century
- Analog Devices Offers Integrated Hot Swap Controller and Digital Power Monitor to Enhance System Protection
- Frequency conversion color TV, frequency conversion technology and progressive scanning technology
- PDIUSBD12 Firmware Programming Guide
- EEWORLD University - UCOS operating system foundation of the Internet of Things
- Smart module PIP keyboard to set real time clock
- A must-know for RF engineers: How to design a directional coupler circuit?
- Wireless communication library micropython-radio
- DSP system design - how to mix 5V/3.3V