Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
1answer
35 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
42 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
59 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
67 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
34 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
78 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
33 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
41 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
33 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
51 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
42 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 ...
-1
votes
1answer
99 views

Handling overflow in micros() [duplicate]

The documentation for micros() says: Returns the number of microseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately ...
0
votes
0answers
22 views

TimerOne and Saving Data to SD Card

I'm using TimerOne.h for collecting sensor (two photocells) data with a frequency of 100 ms and saving the data to a SD card. The file only seems to save data when the computer is connected to the ...
0
votes
0answers
97 views

timer interrupts on an esp8266

Folks. I'm working on an ESP8266 and keen to switch to using: an object approach -> sorted; physical interrupts on the hardware pins -> sorted; timer interrupts -> driving me crazy! My problems are ...
-1
votes
2answers
39 views

Can I use a pot to vary duration of timer circuit without writing code for each time interval? [closed]

I would like to be able to use an Arduino as a timer control to switch on/off a 120VAC load. I think I can do that with the Arduino triggering a small relay controlling the 120V contacts. But I need ...
2
votes
2answers
207 views

Button for Delay Select

My target is to make an Arduino system that is able to change modes with different delays by pushing a button. For example, if I pressed the button, it will go into mode 1 with loop 1 that has a 30s ...
0
votes
0answers
76 views

ESP32 changing PWM duty in ISR

I'm implementing code for a multiplexed 7-segment display (4 letters), e.g. it has two common cathodes and each pin corresponds to two segments depending on which cathode is grounded. I have written ...
0
votes
0answers
38 views

How to generate 4 square signals using Arduino Mega 2560 below 30hz using timers

I would like to generate 4 square signals of different frequencies below 30 hz using timers of Arduino Mega. I was able to generate 30.6hz signals but I have no idea how to generate lower frequencies....
1
vote
2answers
51 views

Please Correct my Delay Code without using delay();

This is my loop()function: if(Serial.read() == 't') { tarestate = true; } while(tarestate == true) { timeNowTare = mills(); if(mills() - timeNowTare >= 3000) { Serial.println("Tare"); ...
0
votes
1answer
78 views

Does enabling the Timer1 CompareA interrupt instantly triggers an interrupt?

I am learning Arduino interruptions and I am unable to explain the behavior of a minimalistic interrupt driven project. The project is the following: an Arduino UNO is connected to two LEDs, on ports ...
0
votes
1answer
85 views

How to find the difference between two timestamps

I'm using this time library to access the properties of unix timestamps like hours / minutes / etc. What I want to do is get the current time, and an estimated arrival time, and find the difference ...
2
votes
1answer
105 views

Triggering a soft reset (Arduino Leonardo)

I want to trigger a soft reset on my Arduino Leonardo, and after some searching settled on using the watchdog timer, as it seemed to be the easiest and cleanest way to do it. However, I don't think ...
2
votes
1answer
135 views

Trying to run Timer1 in ATmega2560 with assembly

I have a slight problem with Timer1 in arduino (ATmega2560) while coding it in assembly. I try to run the Timer1 in CTC mode - I configure everything well in my opinion, but the TCNT1 just doesn't ...
0
votes
1answer
42 views

How to set time for 15 seconds

When user used one password after close the servo the password will valid for 15 seconds then it will not work. Other 9 will be same process Here is code I need just this to set int locker = 13; ...
0
votes
1answer
68 views

Can I use arduino to generate 8mhz frequency ultrasonic pulses in piezo discs?

void setup() { pinMode(freqOutputPin, OUTPUT); Serial.begin(9600); // Set Timer 2 CTC mode with no prescaling. OC2A toggles on compare match // // WGM22:0 = 010: CTC Mode, toggle ...
0
votes
1answer
52 views

Using timer classes within classes

I am trying to develop a class for a pump that works on a stepper motor, it should be simple but its not working the way I thought it would. Once I move the timer object into the class the code wont ...
0
votes
1answer
59 views

What is the smallest duration that can be measured using micros()? [closed]

What is the least value of time that I could measure(count) using micros()?
0
votes
1answer
208 views

how to increase the delay factor of DHT11?

There is no compiler error but output is showing timeout error. as per as the instruction given in https://github.com/RobTillaart/Arduino/issues/61 it says to increase the timeout factor but i did ...
0
votes
2answers
34 views

Timer with ajustable time delay

I have a led strip, and each led should be turned on sequentially, such as this one: [http://1.bp.blogspot.com/-CTT6yvYtdos/VihhhBItwjI/AAAAAAAAAvM/q1jbUylMMdM/s400/ezgif.com-video-to-gif.gif][1] The ...
1
vote
2answers
111 views

Elegoo Nano timer prescaler problem

I am trying to use Timer2 on an Elegoo Nano to produce a "tick" interrupt every 10uS. My plan was to set Timer2 to CTC mode with a /8 prescaler (to get a timer clock of 2MHz from the 16MHz chip clock) ...
0
votes
2answers
38 views

Read sensor data repeatedly after specified time?

I want to read sensor data using analogRead() after every 5ms. I have read other answers to similar questions but what I'm confused about is: let's say, I made a loop to read sensor data using ...
0
votes
2answers
405 views

Getting FFT arduino code to run over 9+ hours, utilizing micros()

I am a beginner in Arduino, coding, and electrical engineering (learning on my own time) and am working on creating an EEG. I've got the hardware down and have managed to get numerical data output ...
0
votes
1answer
95 views

Watchdog Timer for atmega 128

I am using atmega 128 for a smart vehicle tracker. I am trying to use watchdog timer for this controller.But problem is that I have found the maximum watchdog reset time is 2 seconds. I need watchdog ...
4
votes
1answer
378 views

Why are Arduino timer registers not 0?

I'm trying to use the timer registers to do some timing on my Arduino Mega 2560. The output of the following code confuses me: void setup () { // Set up serial connection Serial.begin(9600); ...
3
votes
1answer
72 views

Timer interrupt triggers too often

The following question is based on the Arduino Pro Mini (8MHz, 3.3V) I'm in process of developing (yet another) LED strip driver shield. For that I wrote a simple control loop, that adjusts the ...
0
votes
0answers
65 views

How to enable TIMER/COUNTERS of arduino uno with a push button?

This is my code for stopwatch. I want the timer to start when a push button is pressed. #include <LiquidCrystal.h> #define PIN 2 const uint16_t load = 0; volatile int sec=0; unsigned int ...
3
votes
4answers
771 views

How to make 1 second delay more accurate?

I have written two (1 second) delay programs. The first program as follows: void setup() { Serial.begin(9600); TCCR1A = 0; TCCR1B |= (1<<CS12); TCCR1B &= ~(1<<CS11); TCCR1B &=...
0
votes
1answer
202 views

Generate single pulse from timer 1 in arduino nano

i have a code that shot a single pulse from pin D5 timer 0 (based on josh levine code), it works fine. the code is below #define OSP_SET_WIDTH(cycles) (OCR0B = 0xff-(cycles-1)) void osp_setup(uint8_t ...
-1
votes
1answer
58 views

Arduino code to run 2 thing simultaneously [closed]

I am making a project for my college in which I need to measure the rpm of the motor and show the real-time clock on the 128x64 GLCD simultaneously but when I run the project it only shows one thing ...
2
votes
1answer
396 views

Generating 200 kHz pulse on Arduino Uno in normal mode

I need to obtain 200 kHz from Arduino Uno. I am using Timer0. I have configured it to run in normal mode and the Prescaler is set to clk/8 (the clock frequency of Arduino is 16 MHz). TCNT0 ...
0
votes
2answers
226 views

Inaccurate PWM Signal Frequency and Timing

I have a Teensy 3.2 and I am using the Arduino IDE to program it. I am trying to generate 8 pulses with the frequency of 40 kHz and this needs to be repeated every second. I have written 3 different ...
0
votes
0answers
212 views

50% duty cycle on phase-correct PWM on Timer 2

According to Ken Shirrif's article, Ken Shirriff's blog - Secrets of Arduino PWM (and the same article on the Arduino pages - Secrets of Arduino PWM), under the section Varying the timer top limit: ...
0
votes
2answers
122 views

Unable to obtain pulse train at 32Hz with 20us pulse width with Uno

I tried to obtain 32Hz pulse train(between 30Hz and 35Hz is also fine) with around 20us pulse width with Arduino Uno but couldn't succeed. The problem is: If I do the following: void setup() { ...
0
votes
1answer
380 views

Function Millis() Arduino

I would like to make a countdown with arduino. To do this I'm using the millis () function, but I have a problem, I can not reset this. Reading on the internet I read that it is not possible to do ...
1
vote
1answer
204 views

Timer frequency calculation for UNO/Atmega328

I must be overwrought or something... I just can't get the calculation of the timer frequency right. I have a 16 MHz crystal on the Atmega328. I want 1 kHz timer interrupt rate. So I chose prescaler = ...
1
vote
1answer
139 views

How to add additional millisecond delay to microsecond delay generator

I am trying to make a delay generator. I already found an excellent example in Generating a short pulse after a delay that works in the range from ~5-32767 microseconds (it is limited by a 16 bit ...
1
vote
1answer
415 views

Timer2 Compare Interrupt not working as expected

To get this out of the way first: I have already looked at "Timer2 does not work as it should" and "Timer2 “Clear OC2B on Compare Match” not working as expected in CTC mode" but have not found the ...
1
vote
1answer
328 views

TimerOne Library - Response time

I'm trying to write a library for (rather slow) communication with visible light and have recently tried to include the TimerOne library as a timer. I want to send bits at 2kHz, so with a period of ...
0
votes
1answer
100 views

How to create “Auto switch case”

I am new to programming. I want to modify this sketch and I really need help. I have a switch case in this sketch, and what I want is an auto change effect. In this sketch 18 color effects for ...
0
votes
1answer
193 views

LiquidCrystal library and timers don't seem to be compatible

If I set timer2 to Compare Match mode, my LCD display stops working. If I use Overflow Interrupt it works fine. Here's my test code. I have a loop() function which does its thing, and a timer ...