Skip to main content

What Are Clocks & Timers In Rust?

 What Are Clocks & Timers In Rust?
What Are Clocks & Timers In Rust?

What is a Clock?

  • Computers usage the inner clock to synchronize all of their calculations.
  • The clock confirms that the many circuits inside a computer work together at the same time.
  • The clock, in general, states to a microchip. That microchip controls the timing and speed of all computer functions.
  • In the chip is a crystal. That chip vibrates at an exact frequency when electricity is applied. The direct time any computer is accomplished of acting is one clock. It may be called one vibration of the clock chip.
  • Clock speed is dignified by how many ticks per second the clock makes.
  • The unit of a dimension called a hertz (Hz).
  • The speed of a computer processor is measured in clock speed, for instance, 1 MHz is one million cycles, or vibrations, a second. Similarly, 2 GHz is two billion cycles, or vibrations, a second.

For loop isn’t good for creating delays

  • inline(never)]

fn delay(tim6: &tim6::RegisterBlock, ms: u16) {

for _ in 0..1_000 {}


No Operation

Here is a way to prevent LLVM from optimizing the loop delay: add a volatile assembly instruction. Some instruction will do but NOP (No Operation) is a particularly good choice in this case because it has no side effect. Our for loop delay would become:

  • inline(never)]

fn delay(_tim6: &tim6::RegisterBlock, ms: u16) {

const K: u16 = 3;

for _ in 0..(K * ms) {




Hardware Timer

  • The basic function of a hardware timer is to keep exact track of time.
  • A timer is up till now another peripheral that's available to the microcontroller; thus it may be controlled using registers.
  • Hardware timers are mostly used for timing and counting operations. They allow the processor to carry on with some other process while the timer process runs.
  • A microcontroller has four general-purpose timers. It has a repetitive interrupt timer, and also a system tick timer.


  • One of the basic timers: TIM6 shall be used by us.
  • In our microcontroller, it is one of the simplest timers available.

Registers of TIM6 Peripheral

In this section, the registers we'll be using are:

  • SR, the status register.
  • EGR, the event generations register.
  • CNT, the counter register.
  • PSC, the pre-scaler register.

One Pulse mode

Step 1:

Set the timer through auto-reload register ARR

Step 2:

We have to enable the counter register (CR1.CEN = 1)

Step 3:

We have to reset the value of count register CNT to zero.

On each tick, its value gets incremented.

Step 4:

When the CNT register has touched the value of the ARR register, the counter will be disabled by hardware (CR1.CEN = 0) and an update event will be raised (SR.UIF = 1)

CNT register increase at a Frequency

CNT register increases at a frequency of apb1 / (PSC +1) times per second. Also note: 1 Khz = 1 ms (period)

Organize the Prescaler to have the counter operate at 1 kHz

Where: Formula: apb1 / (PSC +1)


PSC =?

8_000_000/ (PSC + 1) =?

Organize the Prescaler to have the counter operate at 1 kHz

Where: Formula: apb1 / (PSC +1)


PSC =?

8_000_000/ (7_999 + 1) = 1_000 Hz OR 1kHz

The counter (CNT) will increase on every millisecond

Popular posts from this blog

What is Internet of Things (IoT)?

 What is Internet of Things (IoT)?    The internet of Things, or IoT, refers to the billions of physical devices  round the  world that are now connected to  the web  , collecting, sharing and analyses  of knowledge  . It presents and provides the explanation of the network of physical things which is embedded with software , sensors,  and other technologies for the benefit of connecting and exchanging data with other devices and systems on the internet   . Due to the cheap processors and wireless networks, it's possible to  means  anything, from a pill to an aero plane to a self-driving car into  an area  of the IoT. Overview IoT will control the Fourth  technological revolution  . The Fourth  technological revolution  is changing the very software-defined automation allows manufacturers to link all stages of  the worth  chain, rapidly adapt to changing markets , and make highly personalized products on a mass scale. The opportunities provided by this revolution are authenticated

What is Rust Borrowing?

What is Rust Borrowing? Borrowing We call having references as function parameters borrowing. As in real world , if an individual owns something, we 'll borrow it from them . Whenever we’re done, we 've got to offer it back. Referencing  The reference is that the act of consulting somebody or something so as to urge information We would  declare reference in terms of Rust programing as if we are taking a replica of it without damaging or taking its ownership. ‘&’ symbol is employed to pass the reference Have a look that  how ‘&’ symbol is employed in code. fn main() { let s1 = String::from("hello"); let len = calculate_length(&s1); println!("The length of {} is {}.", s1, len); } fn calculate_length(s: &String) -> usize { s.len()} Mutable References The actual concept of mutable reference is same as we use mutable variable When  we  need to  modify  mutable reference is employed once   the worth we make regard to.

Kubernetes Readiness Probes

 Kubernetes Readiness Probes Description We understand that liveness probes and the way they assist keep our apps healthy by ensuring unhealthy containers are restarted automatically. Same like liveness probes, Kubernetes permit us to also define a readiness looked for our pod. The readiness probe is deployed periodically and examines whether the precise pod should receive client requests or not. Whenever a container’s readiness probe returns back success, it’s signaling that the container is ready to simply accept requests. This notion of being prepared is clearly something that’s specific to every container. Almost as liveness probe Kubernetes sends requests to container and supported the result either successful or unsuccessful response it decides container is prepared to require traffic or still preparing for that. The liveness probes not like, if a container fails the readiness check, it won’t be killed or restarted.   This is a very good practice to