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
-1
votes
2answers
45 views

Serial.println() not working in ISR

Please refer my below code, const int led_pin = PB5; const uint16_t t1_load = 0; const uint16_t t1_comp = 43750; int blinkcount; void setup() { // put your setup code here, to run once: DDRB |= (...
0
votes
0answers
24 views

arduino cont down timer in minutes with out using delay

i have one code with delay pleas help me remove the delay i will using this code in air cooler with some sensors delay stop working sensors void startCycle(int cycleTimeInMinutes, const char *type) { ...
2
votes
1answer
86 views

Can't use millis() instead of delay

I am making a home coming/leaving light for car. First I want that whenever I press the car key lock, a timer will start for 10 seconds. And if I press a button twice within 10 seconds, pin 13 will ...
0
votes
2answers
698 views

How to measure ultrasonic sensor without pulsein method?

I am a front-end developer so I don't really know Arduino. Anyway, my teacher gave me a project. In short, I have to measure distance with HC-SR04. But the problem is that the teacher wants me to ...
0
votes
0answers
89 views

Detecting the stop of execution of a timer interrupt

This is my timer interrupt: void setup() { attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), count_time_of_k_pulses, RISING); pinMode(OE_BAR_PIN, OUTPUT); pinMode(S0_PIN, OUTPUT); ...
-4
votes
1answer
38 views

Plotting analogRead on OLED (128*64) - EspWemos D1 mini (Problem to upload this Sketch) [closed]

i want plot real time analog input on OLED . This code for arduino Uno .. i tested on arduino uno and take perfect answer. but i using OLED-Wemos D1 mini Shield board. and i want upload this code ...
0
votes
3answers
73 views

Getting wdt reset + reboots every 5 seconds on simple button/relay code that has worked previously, now it does not and I changed nothing

I have some arduino code I adapted from a simple 2 button 2 relay code I found online. I just multiplied everything so I could have 5 buttons/5relays. I am using a NodeMCU (ESP-12E) for this. I have ...
0
votes
2answers
54 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
32 views

Why does this scope-based timer not work as intended?

I wrote the following scope-based timer to help me profile my code and improve its efficency, but in testing I found that it reports durations far shorter than it should: class CodeTimer { public: ...
1
vote
2answers
76 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 ...
0
votes
1answer
42 views

How can I set a timer?

I would like to set a stopwatch timer that will determine how long an input is in a certain state before changing. I want to set it so that, depending on the output my code executes one of 2 switch ...
0
votes
0answers
47 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 ...
0
votes
1answer
49 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: ...
7
votes
4answers
1k views

Adjust time calculation after Timer0 frequency change

I have an Arduino Nano with an 328P and need all 6 PWM pins. Thus, I had to adjust the prescaler and WGM Mode of Timer0. It is now in phase correct PWM mode with a prescaler of 1. TCCR0A = _BV(...
0
votes
2answers
369 views

Attiny85 Timer 1 comparator B doesn't work properly (while A does)

I'm writing a simple program that is using Timer 1 comparator B to generate a square wave on DEBUG_PIN. So my code at first turns on timer 1 with prescaler 8192 so that one tick is approximately 1ms....
0
votes
1answer
78 views

Unable to compile SimpleTimer code - Exit status 1

I downloaded the SimpleTimer library from the Arduino's library manager and navigated to Arduino Playground website for some sample code for testing - SimpleTimer - Arduino Playground. After copying ...
-1
votes
2answers
456 views

generate two phase-shifted PWM pulses triggered by frequency-divided external signal with Arduino uno?

I have a 4kHz pulse as trigger and I need two phase-shifted PWM output with divided frequency from arduino uno. Now I've managed one PWM output using the following code: int cnt = 0; void setup() { ...
10
votes
3answers
3k views

Could someone explain this weird looking code, used to setup timers?

While looking at sketches other people have written, I occasionally come across code that looks somewhat like this: TCCR1A = 0; TCCR1B = 0; TCNT1 = 34286; TCCR1B |= (1 << CS12); TIMSK1 |= (1 &...
0
votes
1answer
5k 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 ...
2
votes
4answers
6k 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
131 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 ...
1
vote
1answer
797 views

ATSAMD21 sleep + watchdog?

Has anyone got sleep/standby + watchdog to work together on their Arduino Zero or Sparkfun SAMD mini? I am able to get the WDT to reset the device, and am able to put it to sleep - but can't get the ...
0
votes
0answers
28 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
41 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 ...
0
votes
1answer
926 views

Timer0 overflow interrupt not working

I try to use the Timer0 of an Arduino Leonardo (ATmega32u) to trigger an interrupt at regular intervals, using plain avr-gcc (not the arduino library). I try to blink the built-in LED as test, but it ...
2
votes
3answers
10k 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
129 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 ...
0
votes
1answer
25 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
21k 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
69 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
131 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
525 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
47 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
37 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
70 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
518 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
37 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
175 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
282 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
38 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
43 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
30 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 ...
0
votes
1answer
708 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
15k 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
38 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
206 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
2 3 4 5
7