Introducing the arm9 clock and timer

**Preface** This article primarily introduces the clock and timer system of the ARM9 processor, specifically focusing on the S3C2440 microcontroller. Based on Chapter 7 of the S3C2440 manual, it covers a wide range of topics such as power management, clock configuration, USB clocking, camera interfaces, and more. In the following sections, I will elaborate on these concepts in detail. **Introduction** The system clock is the core component that drives the operation of the entire circuit. Understanding the structure of the system clock is essential for effectively using peripherals like timers, UARTs, and others. The S3C2440 processor has four main clock signals: FIN, FCLK, HCLK, and PCLK. - **FIN**: This is the external crystal input frequency, typically low to reduce noise and interference. - **FCLK**: Used as the main clock for the CPU core. - **HCLK**: Mainly used for devices connected via the AHB bus, such as memory controllers, LCD controllers, interrupt controllers, and DMA units. - **PCLK**: Used for low-speed peripherals connected via the APB bus, such as timers, UARTs, and ADB. **Clock Structure** The S3C2440's clock system consists of an external clock input and an internal phase-locked loop (PLL) that multiplies the external clock to meet the processor’s requirements. The external clock is usually kept at a lower frequency to minimize interference. The internal PLL then generates higher frequencies required by the CPU and other components. There are several registers involved in clock control, including CLKDIVN, which determines the ratio between FCLK, HCLK, and PCLK. For example, setting CLKDIVN to 0x03 results in a division ratio of FCLK:HCLK:PCLK = 1:2:4. However, if HDIVN is non-zero, the CPU must switch from fast bus mode to asynchronous bus mode. Here is a sample code snippet for configuring the clock: ```c LOCKTIME = 0x00ffffff; // Use default value CLKDIVN = 0x03; // FCLK:HCLK:PCLK = 1:2:4 HDIVN = 1; PDIVN = 1; // Switch to asynchronous bus mode __asm__( "mrc p15, 0, r1, c1, c0, 0" // Read control register "orr r1, r1, #0xc0000000" // Set to asynchronous bus mode "mcr p15, 0, r1, c1, c0, 0" // Write back ); MPLLCON = ((0x5c << 12) | (0x04 << 4) | 0x01); ``` **Timer Overview** The timer is a peripheral connected to the APB bus and operates at the PCLK frequency. The S3C2440 features five 16-bit timers, with timers 0–3 supporting Pulse Width Modulation (PWM), making them suitable for motor control, LED dimming, and other applications. Timer 4 is an internal timer without external output pins. Each timer has an internal frequency divider, with timers 0 and 1 having individual dividers, while timers 2–4 share one divider. This allows for flexible timing configurations based on application needs. **Timer Operation Example** Let’s take Timer 0 as an example. To configure it: 1. Load initial values into TCNTB0 and TCMPB0. 2. Set the TCON register to manually update the timer registers. 3. Start the timer by enabling the relevant bit in TCON. 4. When the counter reaches zero, it reloads the initial value and triggers an event. For PWM functionality, the comparison value (TCMPB0) can be set to half of the counter value (TCNTB0), resulting in a 50% duty cycle waveform. Adjusting this value changes the duty cycle, enabling precise control over the output signal. **PWM Example Code** Here’s how you can configure Timer 0 for a 50% duty cycle: ```c void timer0_init(void) { TCFG0 = 99; // Prescaler = 99 TCFG1 = 0x02; // Divide by 8 TCNTB0 = 62500; // 1 second interval TCMPB0 = 31250; // 50% duty cycle TCON |= (1 << 1); // Manual update TCON = 0x09; // Auto load, start timer } ``` By adjusting TCMPB0, you can change the duty cycle and create various waveforms, demonstrating the versatility of the PWM function. This makes the timer a powerful tool for real-time control applications.

Spring DIN Rail Terminal

The space-saving design and most optimized wiring are two major characteristics of JST Spring-cage Connection Terminal Blocks.The front Wiring method saves the space between two trunking.

Connect conductors that are vibration resistant,gas-tight,and have long-term stability-with the spring-loaded conductor contacting.Two potentials can be routed in parallel through a terminal point in the double function shaft,Accessories can be used to test and identify.

Supplying wiring cross section: 1.5mm²,2.5mm²,4mm²,6mm²,10mm²and16mm².

Spring Terminal Connector,Spring Loaded Terminal Blocks,Spring Cage Terminal Block,Spring Clamp Terminal

Wonke Electric CO.,Ltd. , https://www.wkdq-electric.com

This entry was posted in on