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
0
votes
1answer
19 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 =...
0
votes
1answer
25 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 ...
-1
votes
1answer
60 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 ...
0
votes
0answers
30 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 ...
0
votes
1answer
18 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
27 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 ...
0
votes
1answer
123 views

DS3231 + button to trigger light

please can someone help me with code, i want to have automatic trigger on specific hour, also i want to have button switch if needed, in my code i can press the button to trigger light relay, but my ...
1
vote
1answer
45 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
25 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
85 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-...
0
votes
0answers
33 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
vote
2answers
90 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 ...
-1
votes
1answer
31 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
1answer
34 views

Running loop for a specific time period

I currently have a loop that runs without a time condition: unsigned long previousMillis = 0; // will store last time LED was updated int WET=4;//wet line int DRY=5;//dry line int Inhale=1000;...
0
votes
0answers
26 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
49 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 ...
-2
votes
1answer
29 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
73 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
90 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
53 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 ...
1
vote
1answer
63 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
80 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 ...
0
votes
1answer
36 views

Aduino mego TIMER1 one second interval

Can someone tell me is this timer is set correct for arduino mega. It should count exactly one second? And why when i print in serial monitor (seconds_passed++) is incremented by 2 not by 1? Full code ...
1
vote
1answer
27 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 ...
-2
votes
1answer
150 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
0answers
37 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
54 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
328 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
59 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
34 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
46 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
217 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
47 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 ...
1
vote
2answers
53 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, ...
0
votes
2answers
155 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'...
0
votes
2answers
59 views

How to drive Arduino UNO as a counter triggered by 555 timer's output (astable mode)

I have an Arduino Uno and a 555 timer configured to astable mode. What I'm trying to do is to program my Arduino to increase a "counter" variable (counter++) everytime it gets triggered by 555 timer'...
0
votes
0answers
25 views

Moving timer-related code into a separate file causing timing inconsistencies?

I have written the following code, attempting to re-implement the Arduino micros function: main.c #include <avr/interrupt.h> #include <stdbool.h> #define CLOCK_CYCLES_PER_MICROSECOND (...
0
votes
2answers
92 views

How to increase the serial port's data throughput

I have an array of numbers that will be subtracted from the ADC readings of a 50 Hz sine wave. Using Serial.begin(57600);, I can only output 25 samples per sine wave cycle, or about 1,250 samples ...
0
votes
1answer
55 views

Arduino Mega - Enabling CTC mode disables timer

I'm trying to use timer3 on an Arduino Mega 2560 in CTC mode. However, enabling CTC disables the code entirely. Here is the function I call in setup() to setup the times. void SetupInterrerupt() { ...
0
votes
1answer
44 views

How do I start a task and have it run for a set amount of time?

I have a project where I need to turn a 24V solenoid on for a set amount of time, then have it turn off. I am rather new to Arduino and not certain how to do this or really where to start. Ideally the ...
1
vote
1answer
273 views

Measure cycle count and time of Digital Input

I am currently working on a project which is read a digital input signal from a machine. The machine operation is as below: when the mold close, the machine gives the "HIGH" signal, when mold is open ...
0
votes
1answer
602 views

set arduino own timer about 5 minutes

I want to program arduino uno by using it's own timer , which instructions and codes should be used if i want timer to be set for 5 minuets and then warn me about an event , the problem is that , the ...
3
votes
1answer
101 views

Why is no PWM signal generated using Timer 2?

I managed to work with timer 0 and 1 but am unable to generate a PWM with timer 2 in my atmega328p. This is the code: #include <avr/io.h> int main(void) { /* PD6 output */ DDRD |= (1 &...
0
votes
0answers
38 views

PWM C Code some logical error

I don't know what's wrong with the code I have activated all the bits I need. I want the code to slowly increase the brightness of the bulb and then reset and then the same thing goes on. Please help ...
3
votes
1answer
108 views

Code test the duration press of the button

I wrote code that tracks the duration of a button click. It has bounce protection and frequent clicks. (Freeze) My code: bool freeze_time, btn_read, debounce; unsigned int freeze_timer, btn_timer; #...
-1
votes
1answer
273 views

Enable and disable individual interrupts

I am working on timer interrupts and external interrupts. for external interrupts I understood the functions like attachInterrupt. detachinterrupt for individual interrupts ,noInterrupts() and ...
1
vote
1answer
68 views

Force TCNT to stay below OCRxA on ATmega328P

I'm using a timer and the TIMERx_COMPA ISR to generate a signal in "the background". This ISR is triggered when the timer reaches a certain value (OCRxA), which in turn can be changed by the user. ...
2
votes
0answers
81 views

What does “Update of OCR1x at” mean in the WGM table of ATMEGA328?

I just finished a reading a couple of online guides on how to use timer registers with pulse width modulation, so I'm still new to its concept. When I looked in the ATMEGA328 specification sheet, I ...
1
vote
0answers
127 views

Millis() is Not Working

I have a sketch that uses two timers using millis() from a library I created to keep time. The timers seem to be working correctly, but when I print the start time of each timer, it is clearly wrong. ...
0
votes
1answer
217 views

timer library on Arduino DUE

I'm trying to call an interrupt routine (let's call it handler() ) every second on my arduino DUE. I thought the simplest way to do this was to use this library but it seems that i don't know how to ...