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
0 answers
24 views

Fade loop glitch

I am working on a little sub program to run a PWM LED. I have a larger program that gives me a non-blocking 10 ms delay. It mostly works well, but I get a -1 thrown during the code execution that ...
-1 votes
2 answers
111 views

I need a 10KHZ PWM signal from pin 3 and 11 using timer 2

The op of pin 11 should be inverse of pin 3. I used digitalreadfast and digitalwritefast and used simple if else. But the delay is high as 10us. What should i do? I found this code in forum but its ...
1 vote
3 answers
2k views

FastLed (WS2812B) and IRRemote problem

I am trying to control my WS2812B with a remote control. To archive this, I am using IRRemote library. The problem is that this two libraries doesn't work together. I did some research and found out ...
0 votes
1 answer
911 views

Having trouble passing data through RF24

I have three RF24, all of them are connected to one arduino-uno each. The first one has sensors that sends data to the second one then the second one passes it to the third one. The first pass from ...
0 votes
1 answer
79 views

Unable to get keypad key in while loop [closed]

I'm a beginner into Arduino so I have a little problem where I'm trying to do a countdown on LCD using while loop but I'm also trying to get a key input inside that same while loop. Problem is that ...
0 votes
1 answer
39 views

Use TCC1 timer to generate PWM on personnal board built with SAMD21E18A

I'm trying to generate a PWM signal from TCC1. I have a personnal board built with SAMD21E18A. I want to use pin 27 PA30, in my variant.cpp I have this line: { PORTA, 30, PIO_PWM, PIN_ATTR_DIGITAL|...
1 vote
1 answer
283 views

Square wave generator generates a shorter pulse from time to time

I am using an arduino Micro to generate 8 square waves on 8 pins. The idea is as follows: on pin 13 is the main square wave. It represents a certain BPM (beats per minute). The other 7 pins should ...
0 votes
1 answer
126 views

Problem with Bing generated code for automated chicken coop door

Glenn from Sweden here. I was wondering if some kind soul could help me out here. My partner bought a cheap chinese knock-off automatic chicken coop door that operates based on sunlight. Link to the ...
2 votes
2 answers
201 views

Using Internal Timer Interrupt to Read Analog Sensor

I'm having difficultly using an internal timer interrupt with my Arduino Nano to properly capture a specific value from a linear potentiometer and then instantly stopping the actuator. I basically ...
1 vote
0 answers
126 views

ESP32 trouble with running ledcWrite inside of ISR

ESP32-S2 (Wemos/Lolin S2 mini) Arduino 2.1.1 on Windows 11 Hello, Thank you for taking the time to read this post and for any assistance you can provide. I consider myself a newbie when it comes to ...
1 vote
2 answers
140 views

Arduino UNO Power interruption

Do you have to upload the UNO after the applied power is disconnected? Does the UNO retain the code without any power? And when the power is disconnected, if the code is retained, will the timers ...
1 vote
2 answers
2k views

Faster TimerOne with Teensy 4.0 (600MHz)

I have a teensy 4.0 which runs at 600MHz, and is double superscaler (i.e. can execute two instructions per clock cycle, sometimes). I need an interrupt to happen faster than every microsecond. I've ...
1 vote
0 answers
179 views

Using library functions in timer ISR ESP32

I'm trying to use a library function in my ISR function that uses the internal timer to trigger every 1 ms. The chip that I'm using is an ESP32-C3-MINI. Here is my current code: main.cpp #include <...
1 vote
1 answer
321 views

50% duty cycle PWM signal with calculated frequency

#include <PWM.h> int led = 9; void setup() { InitTimersSafe(); Serial.begin(115200); Serial.println(); variable_freq(); pinMode(A0,INPUT); } void variable_freq() { while(true) { ...
0 votes
0 answers
144 views

SDI-12 protocol, working with SoftwareSerial

I have a Teros 11 moisture sensor that I have managed to make it work with the SDI-12 arduino library. However, this library does not work with SoftwareSerial and this is critical for me. There is a ...
4 votes
1 answer
16k views

Arduino continuously reading ADC value using interrupt

I have a mono jack audio act as analog input for arduino UNO. The microphone outputs voltage that varies in terms of amplitude (volume) and frequency. In order to get the high sampling rate, I use ...
1 vote
2 answers
342 views

Timer 1 "Set on Compare Match" in Normal Mode - Not working

I'm using the hardware timers on the 328 for phase angle control of a triac with zero-crossing detection. I am encountering some strange behavior with the "Set on Compare Match" feature not ...
1 vote
2 answers
9k views

Using timer0 on Arduino Uno

I am trying to find a simple timer0 interrupt example, but none of those work. Neither this code which I tried to run: boolean toggle0 =0; void setup() { pinMode(8, OUTPUT); cli(); // Set ...
0 votes
1 answer
233 views

DS3231 with Arduino Nano for Timing precision

I am in need to synchronize two separate circuit boards working with Arduino nano. The need is to activate one relay using Arduino-1 after 45 min and another relay using Arduino-2 after 45.36 seconds. ...
8 votes
1 answer
31k views

The difference between "time_t" and "DateTime"

I've run into an issue trying to combine 2 different Arduino timer projects I've found online. For both projects I'm using a DS3231 RTC, but have been able use the DS1307 library just fine in my ...
2 votes
2 answers
204 views

Arudino receiving interrupt command BEFORE entering sleep mode causing it not to receive any interrupt commands in order to wake up

I've written code for an Arduino Nano that when a button is pressed, it sends an IR command. It is set so that if no button press has been received for a period of 10 seconds, it will enter sleep mode ...
0 votes
1 answer
278 views

IMU (MPU9250) and Ticker on ESP32

I want to read the data from an IMU (MPU9250) periodically. To do that I use a ticker as shown in the following code: #include <Ticker.h> #include "MPU9250.h" constexpr int ...
0 votes
1 answer
488 views

Arduino nano timing precision

How precisely can an Arduino nano be timed? The project I am working on needs two Arduino nano to work synchronously. Arduino one have to activate a relay after 2700 sec and Arduino two have to ...
1 vote
2 answers
5k 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 vote
1 answer
94 views

Arduino pro mini sampling rate

what are the possible sampling rate the user can set in Arduino pro mini using ADCSRA registers. I want to set my desired sampling rate through registers, is it possible?
-1 votes
1 answer
167 views

How to read analog sensor data with different timers in arduino

I have three analog sensors like voltage, temperature and pressure. I need to measure the voltage and temperature every 10 ms and I need to measure the pressure alone every 30 ms by using the timers ...
3 votes
2 answers
2k views

Attach the Arduino ISR function to the class member

I intended to use a timer interrupt for limited instances of a class in my ESP32 Arduino project. My first code conception was as follows: portEXIT_CRITICAL_ISR(&lock0); } ...
2 votes
1 answer
81 views

Ramping servo motor taking longer than calculated

I'm learning how to code a "BOE Shield bot" with a partner at my university (first year). To clarify for those that do not know: a BOE Shield bot is a small robot equipped with 2 servo ...
1 vote
2 answers
1k 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'...
-1 votes
1 answer
219 views

How to use TimerOne while calculating time?

I'm trying to get warning with buzzer while I get same values on 3 seconds. But first warning doesn't wait 3 seconds. Second warning is correct. Code is attached. BlinkLED1() method is same BlinkLED2. ...
14 votes
4 answers
53k views

Using millis() and micros() inside an interrupt routine

The documentation for attachInterrupt() says: ... millis() relies on interrupts to count, so it will never increment inside an ISR. Since delay() requires interrupts to work, it will not work if ...
-2 votes
1 answer
245 views

1Hz & 32Hz from 32.768 kHz on ATmega328P at 8MHz & DS3231 32K

I have a 32.768 kHz signal at the ATmega328P input. I need to get 2 signals from this signal: 1Hz and 32Hz. How well will it work? How to do this with a ATmega328P Timer/Counter? What gain will the ...
1 vote
1 answer
390 views

ISR for timer on Arduino MEGA gets called only once

I am trying to write an Arduino code to blink LED using timer 4 on Arduino MEGA (atmega2560). I resetted the timer registers, and entered all the necessary values to bring to 16MHz to 1Hz (rescalar = ...
4 votes
3 answers
1k views

Programming Arduino Uno R3 to trigger a relay once every 24 hours

I programmed an Arduino Uno R3 to trigger a relay once every 24 hours from the moment it is powered on. I calculated milliseconds and used the function delay(). 24 hours * 60 minutes each hour * 60 ...
7 votes
6 answers
5k views

Is it possible to generate an exact 15 kHz clock pulse using an Arduino?

I want to generate a 15 kHz pulse with an Arduino using Timer1, but the problem is that if we want a 15000 Hz clock we need to initialize the timer with 1/15000 seconds or 66.66 microseconds, but we ...
-1 votes
1 answer
491 views

Stopwatch stop/start button and reset

i am trying to make a stop watch with a stop/start button and a reset button i have made this #include "RTClib.h" //Setup the Real Time Clock, DS3231 RTC_DS3231 rtc; const byte SQWinput = 2;...
0 votes
1 answer
2k views

Teensy 4.1 / 4.0 When to use FlexPWM vs QuadTimer pins to strobe LEDs

I want to strobe 3 LEDs (at independent frequencies and duty cycles) via mosfets with a duty cycle of 0.05%-1% at a frequency range of 24-100 hz. I would like to hold 1% or better accuracy for both ...
0 votes
1 answer
4k 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 ...
4 votes
1 answer
634 views

ISR for very fast processes, strange code found. Has ISR effect on timer behaviour?

I found the following code within an example for performing very fast changes on a PWM-output. It works, however I'm wondering about some details. TIMER2 was set up in setup() as follows: TCCR2A = 0; ...
1 vote
4 answers
697 views

How to efficiently code a long duration timer

I'm working on a battery-powered project. I'm trying to write code, which checks the battery voltage every 30 minutes and changes the color of a LED accordingly. Should I still be using millis() or is ...
1 vote
3 answers
1k views

How to save data in arduino when it's power goes off

I am doing a project 'arduino based switch operation'. Here the user needs to set a time to turn on relay and set time to turn it off. The problem is that I want to supply power to arduino using ...
1 vote
1 answer
538 views

Interval timer on Arduino: Doubt about TimerOne library

I want to synchronize a timer interrupt from a button is pressed. I want to read a button state 3 seconds later from the first pulse moment (to identify long pressed button, 3 seconds for this example)...
0 votes
1 answer
109 views

Safely extend TCNT1 / ICR1 to 24 bits using TOV1

I'm hoping to time external events on a '328p Arduino that will occur slowly enough that they'll overflow the 16-bit counter TCNT1. In a different scenario I'd prescale the counter, but I need the ...
1 vote
1 answer
167 views

Where am I going wrong in modifying Timer0 and the ISR interrupts in this example?

(Arduino) Hello I don't know where I am going wrong here, please advise. In the end I want to step a bipolar motor, HIGH/LOW, using Timer0 with OCR0A and OCR0B interrupts to adjust the motors step ...
1 vote
1 answer
83 views

How to set 60 min beeper?

I am trying to make a device that will register latency and number of shocks for passive avoidance behavior in drosophila. My device has two buttons green and red. I press green when I put a fruit fly ...
1 vote
1 answer
930 views

Arduino Mega TIMER1 one second interval

Is this timer set correctly for Arduino Mega? It should count exactly one second. And why when I print in serial monitor (seconds_passed++) is it incremented by 2 not by 1? Full code on Pastebin: ...
2 votes
2 answers
94 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"); ...
1 vote
2 answers
1k views

help explain pulseIn function with arduino and Ultrasonic sensor

dears Engineers.. i got stuck with this issue couldn't understand.. please help with explanations. first i was upset of my ultrasonic sensor reading deviations, that is i examine my sensor indoor and ...
1 vote
0 answers
708 views

Pulse period capture with SAMD21

I need to count the number of pulses in a moving window (e.g. last 60 seconds) using as less CPU time as possible. The first step is to use TCC to capture pulse period. The pulses arrive randomly at ...
1 vote
2 answers
938 views

Turn off Timer1 / Timer1 One-shot

A zero detector crossover sends a pulse to the Arduino, it must start counting x time and then a pulse is sent from the Arduino, once the timer reaches time x, it must stop counting and only start ...

1
2 3 4 5
9