The S3C2440A has five 16-bit timers. Timers 0, 1, 2, and 3 have pulse width modulation (PWM) capabilities. Timer 4 is an internal timer with no output pins. Timer 0 also contains a dead zone generator for high current drive
Timers 0 and 1 share one 8-bit prescaler, and Timers 2, 3, and 4 share another 8-bit prescaler. Each timer has a clock divider that can generate 5 different divided signals (1/2, 1/4, 1/8, 1/16 and TCLK). Each timer module gets its own clock signal from the clock divider that gets the clock from the corresponding 8-bit prescaler. The 8-bit prescaler is programmable and divides PCLK by the load value stored in the TCFG0 and TCFG1 registers.
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 completed. When the timer counter reaches zero, the corresponding TCNTBn value will be automatically loaded into the down counter to continue the next operation.
There are two modes for using the timer. The first is normal timing and the second is PWM output.
Let's talk about ordinary timing first. The general use process of a timer will include these steps
1. Enable the corresponding timer peripheral in the low-power register
2. Set the clock division ratio to obtain the timer's count clock
3. Set the timer value (reload value), configure the middle end, and start the timer
4. Wait for the interrupt to occur and clear the interrupt in the interrupt handling function
Based on these steps, we need to pay attention to the following registers
First, set the division ratio of PCLK to timer. There are two clocks, 01 timer and 234 timer.
Then the second frequency division
You can choose 1/2%201/4%201/8%201/16 clocks. The clock source is divided from the previous register.
Set the timer to automatically reload and start the timer. Note that in this register, you must clear it again after manually updating it, otherwise the timer will not run.
I've encountered this problem before
Set the timer auto-reload value
Then set the interrupt according to the previous interrupt setting method. The timer has no secondary source. Take time0 as an example
1. Source hangs srcpend
2. Interrupt mode intmode
3. Interrupt mask intmask
4. Interrupt suspend intpend
After enabling the interrupt, the timer can be used normally
The specific code is as follows:
TImer.c
#include "TImer.h" u8TImer0Up = 0; void __irqTImer0() { rSRCPND " = (1 < < 10); // Clear source pending rINTPND | = (1 < < 10); // Clear interrupt pending timer0Up = 1; } // Timer initialization // prescaler8 is the divider value, 0-255 // mux timer's strobe input 01/211/421/831/16 // Timer reload value void InitTimer0 (u8prescaler, u8mux, u16count) { rCLKCON | = (1 < < 8); // Turn on timer clock rTCFG0 & = ~ 0xff; // Clear divider rTCFG0 | = prescaler; // Set prescaler rTCFG1 & = ~ (0x0f < < 0); rT CFG1|=(mux<<0);//Set the strobe input//Set the count value of the timer rTCMPB0=0x0; rTCNTB0=count;//Set the initial value//Start the timer rTCON|=(1<<1);//Update TCNTB0 and TCMPB0 rTCON|=(1<<3);//Start automatic reload rTCON&=~(1<<1);//Clear manual update rSRCPND|=(1<<10);//Clear source pending rINTPND|=(1<<10);//Clear interrupt pending rINTMOD&=~(1<<10);//Set the interrupt mode to IRQ mode rINTMSK&=~(1<<10);//Enable timer interrupt pISR_TIMER0=(unsigned)timer0;//Set interrupt address rTCON|=(1<<0);//Start timer 0 }
Timer.h
#ifndef__TIMER_H #define__TIMER_H #include "2440addr.h" #include "led.h" #include "uart0.h" externu8timer0Up; void InitTimer0(u8prescaler, u8mux, u16count); #endif
There are several other registers that need attention when outputting PWM waveforms.
First: PWM output does not need to enable interrupt, but the corresponding pin multiplexing function must be set to PWM function, as shown in the figure, TCLK
Second, to use the pwm function, the compare register must be enabled, that is
Third, see if you need to reverse according to your needs. What is reverse?
It’s TCNT
Pwm.c
#include "pwm.h" //compare the value of the compare register voidTimer0PwmInit (u8prescaler, u8mux, u16count, u16compare) {rGPBCON&=~3;rGPBCON"=2;//Set GPB0 to OUT0rGPBUP=0x0;//Enable pull-up rCLKCON|=(1<<8);//Turn on the timer clock rTCFG0&=~0xff;//Clear the divider rTCFG0|=prescaler;//Set the prescaler rTCFG1&=~(0x0f<<0);rTCFG1|=(mux<<0);//Set the strobe input //Set the count value of the timer rTCMPB0=compare;//compare register value rTCNTB0=count;//set initial value//start timer rTCON|=(1<<1);//update TCNTB0 and TCMPB0 rTCON|=(1<<3);//start automatic reload rTCON&=~(1<<1);//clear manual update rTCON|=(1<<0);//start timer 0 }
Pwm.h
#ifndef__PWM_H_ #define__PWM_H_ #include "2440addr.h" #include "def.h" //compare the value of the compare register voidTomer0PwmInit (u8prescaler, u8mux, u16count, u16compare); #endif
Previous article:ARM4412 bare board drives LED lights, buttons, and buzzers
Next article:Summary of assembly optimization for arm architecture 64-bit (AArch64)
Recommended ReadingLatest update time:2024-11-16 11:25
- Popular Resources
- Popular amplifiers
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
- Share a general good book Digital Signal Processing C Language Program Collection-DSP Algorithm Encyclopedia C Language Version Original Book
- This article explains what parameters and indicators should be measured when designing a switching power supply.
- ATMEL SAM3N2C chip timing is inaccurate
- TMS320C6000 Image Library (IMGLIB)
- I'm just learning about MEMS. Does anyone know what the problem is with the unicleo GUI not being able to recognize the MEMS expansion board?
- MSP430 system clock ACLK, MCLK, SMCLK
- Controlled by "Playpad" + Siri + shortcut commands + XCC3200 (MQTT)
- msp430f5529 dual output pwm wave
- Why should a DC-DC converter be used as close to the point-of-load (POL) power supply as possible?
- Some subway stations in London have codes on their steps!