Questions tagged [timers]

Timers are the hardware in the processor used to count and time events. Use this tag for questions about the hardware timers.

Filter by
Sorted by
Tagged with
2
votes
4answers
7k views

Use timer0 without affecting millis() and micros()

I'm writing a library which needs an ISR to turn off an LED some time after it was turned on. Since it's all about turning an LED on and off it doesn't need to be very precise. On the other hand I ...
-1
votes
2answers
143 views

Detecting when a timer interrupt does not run

I am dealing with code thatt i received that relies heavily on timer interrupts. i am using arduino Mega (Funduino) More specifically, when a signal arrives in a pin, an interrupt is run that starts ...
0
votes
0answers
34 views

FlexiTimer giving errors in servo motion

I am working on a quadruped bot, spiderbot and I am trying to make a creep gait using Forward kinematics however, for some reason my code stops working after the execution of the line - [pwm.setPWM(...
0
votes
2answers
47 views

TimerOne Hanging

For the following program. Compiles and runs. I start the Serial Monitor (shown following code) and it asks me to input the Blink Rate. This runs in setup. Then it enters the loop and prints to the ...
2
votes
1answer
7k views

Button with switch timer and reset time function + LED feedback. What am I doing wrong?

Beginner here. I´ve been trying to implement a button function timer working with millis() instead of delay as I want the button to be responsive while the timer is running. So far I´ve managed to ...
2
votes
3answers
11k views

Using TIMER0_COMPB_vect

I'm trying to understand how to fully use the COMPB vector ISR of Timer0 on the ATMega328 (standard Arduino core). I realize it will make delay() and millis() not work but that's ok by me. I've setup ...
0
votes
1answer
33 views

Missing time when using timer

I have set up Timer2 to count every tick at 16MHz, or 62.5ns per tick. Then I run the following code: int t = 0; for (int i=0;i<64;i++){ data[4*i] = TCNT2; data[4*i+1] = TCNT2; byte now =...
10
votes
1answer
4k views

Setting timer3 in CTC mode - conflict with servo library

I would like to set up a timer in order to call a function 800 times per second. I'm using the Arduino Mega and Timer3 with a prescaler of 1024. To choose the prescaler factor I've considered the ...
2
votes
1answer
22k views

Getting BPM from the given code

I have found code that can blink an LED on Arduino according to Heart Beat. I am using AD8232 as a sensor for Heart Rate. Code for it is: // Variables int PulseSensorPurplePin = 0; // Pulse Sensor ...
-1
votes
1answer
73 views

How to add another time counter to my functioning sketch?

I have a functional sketch that I run on an Arduino Uno, the output controlling a fan module; I need another timer to run a 2nd fan and I would like to use another output on the Uno to do that rather ...
5
votes
2answers
132 views

Trouble with Timer 0

I'm taking my first wobbly steps outside the Arduino IDE and I'm not having much success with timers / interrupts. I can set a pin to output and light an LED with registers fine but I cannot for the ...
0
votes
0answers
31 views

Using interrupts to facilitate time-keeping

I am making a clock on an Arduino Mega using interrupts to facilitate time-keeping. The following is my timer breakdown: Timer0: Used for my calls to millis() which allows me to determine when a ...
1
vote
1answer
608 views

Volatile variable not updating from timer ISR

I know this is a problem that has come up many times but I can't seem to get this code fragment to update the count variable on an ATMEGA328P. I am using an Arduino Uno as a development board, with ...
0
votes
1answer
88 views

Arduino IDE with ATtiny85 error “multiple definition of `__vector_5”

I am having a problem compiling the code for my ATtiny85 circuit. I am using the timer/counter0 in normal mode so that when it overflows it triggers the TIMER0_OVF_vect ISR. When I have that ISR in ...
0
votes
3answers
71 views

ATmega328P - Problem using timer 2 for tone generation

I'm simply trying to use timer 2 for tone generation and what I get is a very faint and strange tone (almost like its modulated somehow as there is a "pulsing" to it). Here's my simple code: #include ...
1
vote
1answer
108 views

Having trouble figuring out CTC on Timer 1 with ATTiny85

I'm using Timer1 on the Attiny85 clocked at 1MHz to toggle an LED every 1 second. However, I'm having some issues regarding prescaler and OSC value selection. I'm using this formula, which I found in ...
0
votes
1answer
553 views

TIMER1 CTC Interrupts not working with avr-gcc

I am attempting to program my arduino in plain C, and I've come across some very strange behavior. If I load the following code from the Arduino IDE, it works as expected and toggles Pin 6 every 100ms....
0
votes
1answer
72 views

Can't get OC1B (pin 10) to output

I'm trying to get this program to use channel B for the output waveform using the phase correct PWM mode and using OCR1A as the top. With a 50% duty ratio I'm attempting to get a 10 Hz freq. I'm able ...
0
votes
2answers
297 views

Making a timer accurate to 1 millisecond possible? Using MAX7219 LED

I'm using the Max7219 (8 digits, 7bits) led display to try and make a timer. I have downloaded an example code from the following site to set the led digits: https://www.brainy-bits.com/arduino-...
1
vote
2answers
613 views

Converting human readable date to a unix timestamp [duplicate]

Can anyone provide a sample code that would convert a human readable date like 2019-10-27 22:10:35 to a unix timestamp like 1572214235? I found many topics about it, but they eider refer to out of ...
0
votes
0answers
46 views

Arduino Due: Measuring the time between pulses

I have a 'pulse train' generated from a photo interrupter and slotted disc mounted on a rotating shaft. My goal is to measure the time between each rising edge. I have looked at the data sheet for ...
-1
votes
1answer
58 views

Trying to create a delay function whilst performing other functions, using Timer.h libraries. Arduino uno

I am having a compilation error saying invalid useof template-name 'Timer without an argument list.
0
votes
0answers
34 views

Alternative for Particle Photon's Timer

I am converting a program made for particle photon to a Mega, everything is working except for the interrupt timer. The code that is of concern is (it's a .cpp file being included in the main .ino) ...
0
votes
1answer
51 views

Variable updated in ISR is miscounting

I'm using a timer to fire a interrupt in configurable time periods. In that ISR, a pin is toggled, and a uint32_t variable is incremented. In the main program, a while loop waits until that variable ...
0
votes
1answer
727 views

Arduino Zero - Stepper control (interrupt)?

I have a stepper controller board that I need to pulse every 40 uS or so. I also have I2C sensors and Serial writes to preform. Currently I run an update call in a tight loop, but the I2C sensors ...
2
votes
5answers
16k views

Creating a timer using a Real Time Clock with start and stop times

I have an Arduino Uno with a motor shield, as well as a DS1307 RTC that I am using to control 2 pumps. Ideally I would like to set a start time (startHour + startMinute) and end time (endHour + ...
-2
votes
1answer
41 views

Can an arduino Uno control led, sound and smoke?

I'm pretty new to this and I've not seen anyone answer this question yet - so I figured I would ask. I have a vape mod that is set up to expel smoke with a trigger. I want to merge this trigger to ...
0
votes
0answers
296 views

Arduino Every 25k PWM signal

I have written a class for generating a 25khz pwm signal for the Arduino Nano. This works great (pin 9 and 10 only) on the Nano. I want to switch to Arduino Every; this code does no longer work (the ...
-1
votes
1answer
168 views

5 minute timer output time remaining

I am trying to create a timer that outputs the time remaining in minutes. I am using an Adafruit Circuit Playground Express. For example, if the timer is 5 minutes, then every minute it should output ...
0
votes
0answers
93 views

Send ECG data using buffer in real time to the server without using delay

I am trying to make a ECG monitoring system using Arduino, GSM and ECG sensor which data should be sent to the private server in real time. Those data are then collected via Matlab on the remote ...
3
votes
3answers
13k views

Stable frequency generation

I'm trying to work out the best way to generate a stable frequency with my Uno R3 I'm using interrupts to generate an approximately 40KHz frequency which drives some ICs/MOSFETs to effectively ...
1
vote
1answer
104 views

Set PWM by period? And have it variable?

In this other stack QA I'm asking about generating a pulse signal with a period ranging from 63 ms to 6.5 ms. There is a popular PWM library however it doesn't compile and also since 63 ...
0
votes
2answers
175 views

control 3 relays with 1 button

Is there a way to control 3 relays with 1 button? My idea is: There are 3 modes; mode 1 for relay 1, mode 2 for relay 2 and mode 3 for relay 3. With a long press you switch between modes (After 3 ...
1
vote
0answers
1k views

Arduino stops working after some receivings from RF

I made a sketch that receives an rgb code from a remote Arduino using nrf24l01 and while it works for the first receivings then it stops working. I placed a testing Serial.println in the loop to test ...
-2
votes
1answer
512 views

how to set buzzer on and off

I have a project that require me to use magnetic contact sensor. I will put the sensor at the door. So the idea is i want every time someone open the door, the buzzer will make a sound, but it will ...
1
vote
1answer
28 views

Check if a set of events occur in a limited time period

I am making a project in which I am using 4 Infrared sensors to take an input. The way I want it to work is such that when one of the sensors is triggered, the code listens for input from the other ...
1
vote
0answers
51 views

Turning on controller with button and turning off with a timeout

I am making a device controlled by an ESP 8266 and am wanting to save power by having it power down when not in use. The desired behavior is for a momentary button press or vibration sensor activation ...
1
vote
2answers
98 views

maximum interrupt-based PWM frequency at 500 Hz

I need to control a 24 kHz ultrasonic transducer and decided to use an arduino uno I have lying around. Using tone() or the atmega's hardware pwm is not very suitable because I need two 50/50 square ...
0
votes
1answer
1k views

Timer Countdown to control relay (multiple functions in void loop)

I'm trying to build this project with a simple code. Object is to hit up button to increment minutes or down to decrement minutes then hit start to start countdown, while its counting relay will turn ...
0
votes
1answer
98 views

How to code 4 relays to go off in intervals and not in sequence? [closed]

Code : //FOR AEROPONIC SYSTEM WITH ROOM TEMPERATURE AND HUMIDITY SENSOR //AND 4 GROW CHAMBERS WITH DIFFERENT SPRAYING TIME // RELAY CONTROL #define RELAY1_PIN 2 #define RELAY2_PIN 3 #define ...
0
votes
1answer
52 views

RDTSC alternative for Arduino

To calculate an operation execution time, I was saving the millis() result before and after the operation to calculate the interval time. Is there an alternative on the Arduino Uno like the RDTSC ...
1
vote
1answer
66 views

Arduino Timer0 Piggyback

As described here https://learn.adafruit.com/multi-tasking-the-arduino-part-2/timers I use timer 0 to get my own timer with a milliseconds resolution. It is setup like this: void setup (void) { ...
2
votes
1answer
459 views

Arduino Timer with increase time button

I have an Arduino project to do, which requires a countdown timer(which I've already done). I connected a push button, and when I press that button I need it to increase my countdown timer by +10 ...
0
votes
0answers
84 views

Why does my TFT keep turning white after moments?

Alright, seems there is something wrong I am doing that I don't understand. Before I start explaining, my question is different than this white screen question. First of all my TFT ST7735 is working ...
3
votes
4answers
17k views

How do I count time in seconds?

I have a statement: if(control > 100 && control < 130) { //count time 30 seconds and open pin1 for 3 seconds. } How can I count 30 seconds and open a pin for 3 seconds?
1
vote
2answers
100 views

Start / end events using milis

I want to start a relay, have it run for 3 seconds, stop for 10 seconds, repeat. I can't use delay, because I have a motor driver starting / stopping every 100 milis. So I put together this code, ...
1
vote
0answers
874 views

ATtiny85 Comparator C interrupt on timer 1

I have a program that uses Timer1 comparator A in CTC mode. I realize that I need to set OCR1C for the timer to reset at given value. However there is no such thing as an interrupt generated by timer1 ...
9
votes
6answers
33k views

Very long delay() possible?

I'm trying to make an opening and closing little door that should open or close every 12 hours. I was wondering if I could just make a small looping script with a delay() for 12 hours, delay(43 200 ...
0
votes
2answers
373 views

esp8266 deep sleep timer slightly inaccurate?

I'm making a door open timer using a hall sensor and have a wemos d1 mini that uses a deep sleep to sleep for 1 minute after checking the hall sensor state and printing the value on the serial port. I'...
2
votes
0answers
1k views

Timer CTC Set and Clear modes — How to un-Clear and un-Set?

Nick Gammon's cheatsheet for the Ardunino UNO's ATmega328P (below) shows some hints on the Clear Timer on Compare (CTC) modes of AVR chips. Most of the examples for CTC mode I find use the COMxxx ...

1
2
3 4 5
8