Timer/Counter & Interrupt for Accurate Time Control on Arduino UNO R3

MURRAIYA·2024년 2월 28일
0

Intro

This post is about Timer/Counter and Interrupt of Arduino for accurate time control. If you are working on time sensitive project, Timer and Interruput would be better than delay() function.

I used Arduino UNO R3. But I explained the whole process in general from finding MCU model.

💍Find Datasheet

To use timer and interrupt, you should access to the register of MCU. We need datasheet of our MCU.

🙄What's my MCU model?


MCU of UNO R3 is ATMega328P. Memory of timer and interrupt differs by MCU models. Find yours if you use different model.

🙄Find datasheet of your MCU

Now find datasheet of MCU.
FIND DOCS ON OFFICIAL WEBSITE ALWAYS!!

In ATMEL site, I searched ATMega328P.
This is what I used.

💍Timer/Counter


Searching "Timer/Counter", my MCU has two 8-bit timers and one 16-bit timer. What's the difference? Choose appropriate one for considering formula below.

🙄Choose Parameters for 20Hz Output

params

fOCnxf_{OCnx}: Output Frequency You Want (Hz)
Fclk_I/OF_{clk\_{I/O}}: Clock Frequency of Timer/Counter (32MHz for ATMega328P)
NN: Prescaler
OCRnxOCRnx: Top Value (to find!)

Top이 그 머야.. bit 수 머시기

fOCnx=Fclk_I/O2N(1+OCRnx)fOCnxFclk_I/ONOCRnxf_{OCnx}={F_{clk\_{I/O}}\over 2N(1+OCRnx)} f_{OCnx} F_{clk\_{I/O}} N OCRnx

In my case, it was for external trigger of multi camera time sync.

cont.....

profile
🙃SUJI KIM🙃 🚩 Inha University Undergraduate 🚗 Autonomous Driving Robots 📷 Computer Vision 💫 SLAM

0개의 댓글