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
27 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 ...
user avatar
4 votes
1 answer
569 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; ...
user avatar
  • 566
1 vote
4 answers
97 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 ...
user avatar
3 votes
1 answer
338 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); } ...
user avatar
0 votes
1 answer
36 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 ...
user avatar
  • 221
1 vote
1 answer
120 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)...
user avatar
  • 113
1 vote
1 answer
59 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 ...
user avatar
1 vote
0 answers
121 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 ...
user avatar
  • 209
0 votes
1 answer
69 views

Why do I get different times when using analogRead() inside while loop?

I have the following code which checks the latency of another board. int triggerPin = 13; int dataPin = 9; int ejectorPin = A0; unsigned long t_start = 0; unsigned long t_end = 0; ...
user avatar
  • 3
1 vote
1 answer
58 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?
user avatar
  • 21
1 vote
1 answer
50 views

I am trying to add a countdown to my Arduino code but it does 0 days, 04:09:36 instead of starting at 7 days

The code I use probably has a math problem since an Arduino can only count a 16 bit integer. This problem is with the WeekDelay() function. The project is for an Aerogarden. It pumps water into the ...
user avatar
-1 votes
1 answer
120 views

I have been having a lot of trouble adding a countdown to a piece of code [closed]

This is the code. The /// are where I added the countdown. Unfortunately the countdown only goes down 9 seconds. What I want it to do is go down the full 24 hours. I have been trying to fix this error ...
user avatar
-1 votes
1 answer
59 views

Can't get 1 second on a ATMega168 timer

TCCR1A = 0; TCCR1B = 0; OCR1B = 0xFF00; TCCR1A = (1<<WGM10) ; TCCR1B = (1<<CS12) | (1<<CS10);; //set the pre-scalar as 1024 TIMSK1 = (1 << OCIE1A); This doesn't ...
user avatar
-1 votes
1 answer
40 views

Cannot change pointer for port in main loop

I am testing on an Arduino UNO. I want to use timer1 and interrupts to create various LED patterns. The LEDs may span multiple ports i.e PORTB and PORTD. I want to use a "volatile uint8_t*" ...
user avatar
1 vote
0 answers
66 views

Millis() based timer program for 24x7 usage in Arduino [duplicate]

I have made an irrigation system using Arduino. Timer program is based on comparing the previous Millis() and current Millis(). I want to know the chance for error when the currentMillis() overflows ...
user avatar
0 votes
1 answer
88 views

Timer to send a periodic pulse [closed]

I am looking for a very low power, small component (perhaps an arduino) that will send a pulse 3.3V logic HIGH pulse once every X seconds to another system. I want to be able to configure X (maybe a ...
user avatar
  • 170
3 votes
2 answers
469 views

MPU6050 Arduino Jeff Rowberg library interrupt Issue

I was trying to get the data from MPU6050 using the Arduino library mentioned here. The following code is an edited version of the sample code given in the library folder which seems to be working ...
user avatar
  • 171
1 vote
0 answers
92 views

Variable frequency PWM, without changing timers

I need variable frequency output - 0-5000Hz with some duty cycle. I do not want to change timers, because I am using delays, serial and CAN, so I do not want them to be affected by changed timers. I ...
user avatar
  • 11
2 votes
0 answers
149 views

External Interrupt and Input Capture pin | Arduino MEGA

I have a code for finding the rpm of one system calling here as engine , the engine have a hall sensor output and I have tried the following Code #define SERVO_MIN 2000 #define SERVO_MAX 4000 struct ...
user avatar
  • 171
0 votes
1 answer
595 views

Seeeduino XIAO write and read PWM duration (period) using timers

I am trying to communicate between two Seeeduino XIAO (chip: ATSAMD21G18A-MU) by way of TCC capture using register timers. Square wave pulse duration varies from 200ns to 4us. I found these two code ...
user avatar
  • 177
2 votes
0 answers
72 views

Is a PWM phase duration set with OCR1A a reliable way to communicate values to other Arduinos?

I am working on communicating 4 switch states across multiple Arduinos using only one pin. It must be as fast as conceivably possible. Currently I have a master Arduino reading all 4 switches (...
user avatar
  • 177
1 vote
1 answer
69 views

Interrupt takes longer than expected [closed]

I am trying to write a delay function in C, which should take 0.5 seonds then carry on. I am aware that there are libraries for this purpouse, I want to make it myself. #include <avr/interrupt.h>...
user avatar
1 vote
2 answers
641 views

Arduino Reset via Software (every day)

Dear Stack Exchanger's, I want to reset my Arduino and system in every 24h for preventing frozen software and also other connectivity stuffs. I wrote a program which connects a digital pin to reset ...
user avatar
1 vote
2 answers
101 views

run a function for a certain amount of time! [duplicate]

i'm working on a project where i need to run a function for 20 minutes and the function writes to memory using EEPROM every minute. How can i make the function run for 20 minutes, i was thinking of ...
user avatar
2 votes
1 answer
79 views

How can I read the Timer direction in phase correct PWM?

I have had to use Timer0 with phase correct PWM and a prescaler of 1. This results in a 32khz PWM frequency and obviously impacts millis, delay and micros. (Timer1 and Timer 2 are also in use so ...
user avatar
  • 51
1 vote
0 answers
27 views

How do I synch the Arduino PID library with an external timer for turn-rate control?

I have been trying to use the Arduino PID library for controlling the rate of turn (in deg/sec) of a wall-following robot. The robot's operating system uses TIMER5 on an Arduino MEGA2560 to update a ...
user avatar
1 vote
1 answer
68 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 ...
user avatar
  • 11
1 vote
2 answers
156 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 ...
user avatar
2 votes
0 answers
31 views

Generating Externally Triggered Complimentary PWM with Arduino Due

I need a 2KHz complimentary PWM waves with adjustable duty and phase that is triggered by an external 4KHz source. After reading the datasheet I think there might be 2 way to do this: Use a TC unit ...
user avatar
  • 209
2 votes
1 answer
219 views

Arduino Uno's Timer maximum frequency using Timer Compare Interrupt, not Timer Output Pins (e.g. OC0A)

I want to achieve the generation of a custom binary signal over a digital pin at the highest possible frequency on Arduino Uno. Using Timer's output pins (e.g. OC0A), one can get a pin to toggle at a ...
user avatar
1 vote
0 answers
112 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 = ...
user avatar
1 vote
2 answers
113 views

How to convert kitchen timer code into a countdown

I found this code for a kitchen timer, it was the closest thing to a countdown. The code is here: #include <LiquidCrystal.h> const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; ...
user avatar
2 votes
2 answers
112 views

How to program an Arduino Uno to collect data using a timer interrupt and analyze that data in matlab?

I working on a project where I want to collect sensor data (from a sensor) and I want to analyze the first 20 data sample (e.g., find the range, trendline e.t.c.). I know how to compile a timer ...
user avatar
1 vote
0 answers
86 views

Arduino mega PinChangeInterrupt with 16 bit timer

With reference to this question ::I have written a program by using 16-bit timer, The program is as follows . volatile uint32_t ovfCount = 0; struct Pulse { uint32_t last_toggle; uint32_t width; ...
user avatar
  • 171
1 vote
1 answer
146 views

Issue using Arduino Mega Timer2 with PinChange Interrupt

I was working on a program to measure the pulse width , for that I thought of using Timer 2 in Arduino mega along with pin change interrupt, The program I have written is as follows volatile float ...
user avatar
  • 171
1 vote
2 answers
87 views

Timer Interrupt Collision

I am working with a MEGA2560 trying to implement velocity ramps for three steppers at the same time. The goal is to move to different positions applying accelerations and decelerations while finishing ...
user avatar
1 vote
2 answers
585 views

How to exit out of a timer interrupt (ISR(TIMER1_COMPA_vect))

I have a code here where I collect an array of data and do some data analysis with the data. The only thing I'm struggle with is how to exit the ISR after I am done running my code. I am using a pre-...
user avatar
1 vote
1 answer
96 views

Input Capture Mode PPM signal

Greetings to all members of the Forum. I would like to express my deepest gratitude, with respect to the title of this post. The last week I am trying to capture and decode a PPM Signal from an RC ...
user avatar
3 votes
2 answers
346 views

Is it bad practice to multitask without timing constraints

Going through resources such as several things at the same time and with some greatly appreciated assistance on here I'm finally getting a grasp on how to multitask a microcontroller. Most examples ...
user avatar
1 vote
1 answer
97 views

Doing several things at the same time with functions, objects or interrupts?

First of all, thank you for taking the time to read this. I am a newbie, so apologies (done examples on arduino website, basic C++). I'm trying to get an idea of what the best way to structure a ...
user avatar
1 vote
1 answer
84 views

Issue with simple timer based on millis()

Sorry to bother but I am at my wits end. I'm experimenting with timers, and starting very simple. The following code is supposed to print the content of a variable each time an interval of time has ...
user avatar
1 vote
1 answer
1k views

4 Bit Counter up and down

we are asked to create an Arduino code that would run a 4 Bit Binary UP counter once a push button switch is pressed and then 4 Bit Binary Down counter on the second click. Then vice versa. This ...
user avatar
0 votes
1 answer
51 views

LF: flexible scheduler/timer library

I'm working on a few arduino projects where I've needed a flexible scheduler and/or timer library and was wondering if anyone has a library they recommend? Case 1: I have a sensor that needs to ...
user avatar
  • 1
1 vote
2 answers
271 views

Switch on the piezo emitter for a short time

I need a short beep for every minute of change. I wrote a separate function. The signal duration should be 50 ms, the rest of the time the emitter connected to the A1 contact should be silent. A ...
user avatar
2 votes
1 answer
39 views

Can Arduino uno adjust input square wave duty, phase and frequency with just timer-counter?

Requirement: I have input 4KHz pulse input Divide it's frequency in half Arbitrarily adjust phase Arbitrarily adjust duty Out put the modified pulse My solution (CPU): uint8_t cnt = 0; uint16_t t1 = ...
user avatar
  • 209
1 vote
1 answer
127 views

Time signal. Determine the presence of pulses and their duration [closed]

I want to detect the exact time signal from an FM radio station. The signal is transmitted in the form of 5 short pulses and one long one. My task is to determine the presence of a pulse in the audio ...
user avatar
6 votes
6 answers
3k 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 ...
user avatar
  • 83
0 votes
2 answers
83 views

Turn on relay for amount of time by continuous input

I have a project having two input status first the input is not continuous the output buzzer relay will be on for 10 seconds and then turned off or it can be off directly by push button the second ...
user avatar
0 votes
1 answer
167 views

Initialising timer interrupt crashes Mega 2560

Below is the entirety of my prototype code, the cycling of pin 13 is what I use to confirm the board is restarting. The board resets continually on this implementation of initialising the interrupt. ...
user avatar
  • 293
1 vote
0 answers
62 views

How to implementing timer interrupt with a sensor device using A0 and A1 pins

I was wondering if there is a way to program a timer interrupt to collect sensor data at a specific sampling rate? I want to attach two strain gauge sensors to A0 and A1 pins and collect the data at a ...
user avatar

1
2 3 4 5
9