Questions tagged [timing]

This tag is for questions about timing code execution, or external events.

Filter by
Sorted by
Tagged with
-1 votes
2 answers
152 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 ...
Pranav Pillai's user avatar
0 votes
2 answers
53 views

Serial Buffer stays empty as soon as it becomes empty once

I have a question regarding serial buffer readout. At program start, I send a serial command to a sensor that 1. activates him and 2. let him send data - that works. When I unplug the sensor, the ...
Gymknopf's user avatar
0 votes
2 answers
123 views

best practice for performance: empty loop() when using interrupt?

I'm working on a little midi hardware project and I'm using attachInterrupt() to assign a callback function to an interrupt pin. Nothing gets done in the loop function, so it looks like this: void ...
strudelkopf's user avatar
2 votes
0 answers
100 views

I goofed: I used a digital output rather than an analog output

OK, I have a little hardware issue I need to fix in software for the time being. I say, "For the time being," because I already have the PC Boards printed, and I need to make do for this ...
Leslie Rhorer's user avatar
-1 votes
1 answer
355 views

delayMIcroseconds and micros execution time not explainable

i just experimented with the timing accuracy of my Arduino Uno R3 using this code: unsigned long beginTime; unsigned long endTime; void setup() { Serial.begin(9600); // open a serial port } void ...
Michael S's user avatar
  • 101
0 votes
3 answers
201 views

Arduino Timer Drift Issue

I have two Arduinos that communicate over serial. Each arduino runs a TDMA algorithm where each arduino is assigned one timeslot. The arduinos should transmit during their timeslot, which does work ...
roberthayek's user avatar
1 vote
1 answer
98 views

How can I SPI "Latch" (LE/CS/SS) for a specific number of SCLK cycles?

Context I am working on a project which includes 13 cascaded STMicroelectronics LED1642GWs. These LED drivers are essentially 16bit shift registers, whereby the buffered serial data can be loaded to a ...
George Kerwood's user avatar
3 votes
1 answer
755 views

How do I run 4 LEDs sequentially based off of a push button input?

I am trying to create a program that runs 4 LEDs sequentially while also being able to do other things with different inputs and outputs. Because of this, I am using the millis function and not the ...
Myles's user avatar
  • 73
-1 votes
1 answer
34 views

Synchronizing an internal frequency to an external one

In this question: Procedure for changing frequency of Nano or similar, @EdgarBonet gave a very nice method of generating timings that don't divide the system clock evenly. He also said that it would ...
Jim Mack's user avatar
  • 235
0 votes
1 answer
109 views

How fast does the Arduino execute code?

I am using the Arduino Nano every. Take this example where I am measuring two things A and B. Loop{// this loop runs once every second //Read A,B //Change something using analogueWrite which ...
fred's user avatar
  • 101
2 votes
1 answer
147 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 ...
Simm's user avatar
  • 51
2 votes
1 answer
337 views

Obtaining angular velocity from quaternion data (BNO055)

I'm able to get quaternion data from the BNO055 sensor, and would like to convert these to angular velocity for my project. I know you can pull the gyroscope directly for the data, but from what I ...
Zhelyazko Grudov's user avatar
1 vote
2 answers
109 views

How can I execute two functions at the same time?

#include <Servo.h> Servo myservo; int pos = 0; int servo_pin = 3; int led_pin = 4; void setup() { myservo.attach(servo_pin); Serial.begin(9600); pinMode(led_pin,OUTPUT); } void ...
Yusuf Muharrem Daşkaya's user avatar
2 votes
1 answer
101 views

Relays just switch ON and OFF on delay(), not on millis()

I use fuzzy logic for the running time of relays, but the relays just switch ON and OFF at the interval of the delay() I put at the end of loop. This is my code: void loop () { ph = -180/100.0; ...
daffa faiz's user avatar
2 votes
1 answer
237 views

Help with millis to get accurate timing

I'm essentially trying to create a music box which is light activated using an LDR. When it's open a song plays, while a servo rotates a figurine back and forth, and an LED dims and illuminates in ...
TonyStark's user avatar
-1 votes
1 answer
560 views

how can I stop my Arduino code after 1 second?

I want to send message NRF24L01 to NRF24L01. I want to see if I can send just one second. How can I stop code after 1 second?
Mahmut Polat's user avatar
-1 votes
1 answer
78 views

Issue using micros() instead of millis()

I have two function implementations that I expected to work the same: #define HEAD_STEP_DELAY 1000 unsigned long HeadLastMicros; void HeadUpdate() { if ((micros()>=HeadLastMicros) && ((...
smbaker's user avatar
  • 19
13 votes
1 answer
2k views

_delay_ms() is much slower than expected (by a factor of 6) on TinyAVR 0/1 (ATTiny1604)

I designed a custom AVR development board using the Atmel ATTiny1604 microcontroller. It belongs to the new Tiny-0 family, due to its recentness, some required changes to relevant toolchains have yet ...
比尔盖子's user avatar
0 votes
1 answer
2k views

Running a DC motor for a set amount of time

I am trying to run a DC motor for 100ms and then turn it off completely. Here is my code any suggestions on why it might not be working? My Code const int pirPin = 9; const int motorPin = 2; int ...
Erin Rehm's user avatar
3 votes
2 answers
125 views

Switched from 3ft to 10ft connection wires. My setup doesnt run correctly now. Timing issues?

Running a DC motor(6.5A max input), motor driver (MD10C 7Amp peak output), and Arduino Mega. I am stabilizing an object with an accelerometer as my sensor. I switched to longer wires so I can have my ...
Thunder Dornhofer's user avatar
1 vote
1 answer
48 views

Sequencing air pistons proble - Help please?

I am a beginner trying to activate 2 sets of 3 air pistons sequentially by going through the YouTube Tutorials... Help, please, pretty please?? :-) There are 3 sets of 2 pistons, each set working in ...
Michael Buet's user avatar
0 votes
2 answers
992 views

How do I make my LCD screen scroll text while allowing for button input?

Here's what I want my code to do: This is part of a tea infusing project that would automate the steeping of tea, part of this is initially having a selection of either Black/Herbal tea or White/Green ...
thatgenericguy's user avatar
0 votes
1 answer
70 views

ESP8266 CCLOCK Odd behavior

I'm trying to write some extremely fast code for the ESP8266, so I'm trying to figure out how to time things. I've discovered CCLOCK, a register that reflects the number of clock cycles since startup....
Erhannis's user avatar
  • 103
1 vote
1 answer
37 views

How do I set a variable so that after a condition is met the loop ignores input?

I have a analog inputs to my Uno that I am cleaning up and using to keep a digital pin high until the output drops to zero. At this point I want to stop reading that input because it may come back up ...
Jeremy Brown's user avatar
-1 votes
1 answer
473 views

Is the shiftOut code depending on the (low) speed of an Arduino?

In the (official) file wiring_shift.c I found the following code for shiftOut: void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) { uint8_t i; for (i = 0; i < ...
Michel Keijzers's user avatar
0 votes
2 answers
78 views

Timing taking longer than expected

This is on a custom Arduino PCB (32u4) that I am programming with a Sparkfun Pocket AVR Programmer. A different program that I was writing wasn't working the way I expected it to, so I tried the "...
Tri's user avatar
  • 73
1 vote
1 answer
291 views

Can I get some help with a metronome code on my arduino uno?

ok so I dont actually know anything about coding or electronics outside of being an electrician. This is something i've been working on for about a month. I may be asking something dumb but here it is....
tom's user avatar
  • 13
1 vote
3 answers
180 views

When GPS can't see satellites, how can I continue to tick off a smooth-ish time?

I'm getting 10 updates/sec from my GPS unit (The MTK3339 used in the Adafruit breakout board), and using it to update a clock display. This works well enough, though there's one minor problem that I'd ...
Sniggerfardimungus's user avatar
-1 votes
1 answer
301 views

Does DmxSerial stops interrupts?

I am trying to build a setup with an Arduino Mega, having a DMX output (using DMXSimple library), and a MIDI library (to be done). I was wondering, if I get into problems. According to This question, ...
Michel Keijzers's user avatar
0 votes
1 answer
360 views

Arduino timer to turn a serve at a certain time

i am working on a project for my school tech class. Our goal is to make a vehicle that will travel along a cable and drop an egg to a target while going down the cable. i am using an arduino to to ...
Mehmet Haspolat's user avatar
-1 votes
1 answer
246 views

Using mills() in place of delay() on relays not getting solid switch over

I know I should post some code that maybe cleaner but really I am just in need of a answer to a problem I seem to run into a lot when using mills() in place of delay(), whilst making a Christmas light ...
Ron Needham's user avatar
1 vote
1 answer
2k views

How to randomize the delay in Arduino Stepper code?

How does one add a random DELAY between 10 and 20 seconds? For example in the following stepper logic I have a delay of 11 seconds - expressed in milliseconds as: delay(11000). What would I need to ...
ebucket's user avatar
  • 13
0 votes
1 answer
216 views

Measuring lenght of time light levels peak using photoresistor

I'm trying to measure shutter speeds on old cameras. This essentially consists of: Shining a torch at one end of the camera putting the photoresistor at the other end trigger the shutter which ...
sam.cooper645's user avatar
0 votes
1 answer
1k views

Strange discrete errors when reading HC-SR04 sonar sensor

I'm experimenting with an HC-SR04 sonar sensor. Basically I'm measuring the distance to a cardboard box twice a second with these lines of code running on an ESP32: unsigned long sonarMeasure() { ...
Falko's user avatar
  • 103
1 vote
1 answer
982 views

Atmega328P Prescaler to Microseconds

For a bitbanging project I'm working on, I need to measure microseconds as accurately as possible. The function micros() won't work for me here because of the unpredictable times at which it might ...
Bo Thompson's user avatar
9 votes
3 answers
2k views

delay(time); vs if(millis()-previous>time); and drift

Going through an old project, I had code on two Arduino Due that looked like this void loop() { foo(); delay(time); } taking to heart the majority of literature on using delay(); I recoded this ...
ATE-ENGE's user avatar
  • 931
4 votes
4 answers
11k 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 ...
noearchimede's user avatar
1 vote
3 answers
107 views

Arduino not recognizing when a timer reaches 0

Alright, so I'm attempting to make a timer that will turn on a light after an hour. Currently I have it set to 5 seconds for testing. What is happening is whenever I start the program it won't ...
Jayjaxx's user avatar
  • 113
1 vote
4 answers
4k views

Arduino Blink two LEDs without Delay(amount of repetitions)

Arduino community. I have had experience with Arduino for 3 years now and have finally come to the conclusion to get rid of the delay function entirely. Below is the code to blink two LEDs a ...
Nathan Ramanathan's user avatar
3 votes
3 answers
1k views

Control time without delay() Arduino

For the last couple of day I've been trying and failed many times just to not use the delay() funtion in Arduino. I have to admitted that my coding skill are extremely bad. What i trying to do is: If ...
zuzu's user avatar
  • 55
0 votes
2 answers
307 views

Buffering output stream

I'm looking to toggle a pin on and off in a fast and timing-sensitive manner, and I'm wondering if the Arduino Uno has any built in "buffers" that would be able to hold a set of values and send them ...
user avatar
1 vote
1 answer
80 views

Carry out two consecutive tasks when a button is pressed

I'm building a project that has 2 motors. What I want to do is: When button is pressed (hold down through RF controller) then: Run motor A on pwm at 50 for 1 second Run motor B on pwm at 255 for 1 ...
zuzu's user avatar
  • 55
0 votes
2 answers
322 views

Hardware damage from executing tight polling loop over extended periods of time?

I want my project to be standing by at the ready for months and years at a time, so I started writing my code to throttle back from polling at delayMicroseconds to just delay. Like, after 15 minutes ...
user avatar
3 votes
3 answers
893 views

Ensuring specific frequency at specific time?

I, at the moment am trying to come up with a simple way where I can program an Arduino to provide a step signal with a given frequency, at a specific time. The frequency has to be ramped up, and ...
Carlton Banks's user avatar
0 votes
2 answers
224 views

Sketch does not work without delay() or other complex functions like digitalWrite()

I have a simple sketch here that should just blink a led once a second or so (approximately): boolean onOff=true; int count=0; void setup() { pinMode(13, OUTPUT); } void loop() { count++; ...
user2882440's user avatar
1 vote
1 answer
2k views

analogRead() takes >400 us on Arduino Zero but ~100 us on Uno, why?

I've been trying to figure out why the analogRead() function takes about four times as long on an Arduino Zero than on an Uno, when the Zero has a faster clock than the Uno. Arduinos website says ...
hiitsali's user avatar
1 vote
1 answer
1k views

Force compiler to execute instructions sequentially?

Is there a way to force the Arduino compiler to compile individual commands sequentially? Looking at the disassembly, lines of the assembly code for different C/Arduino commands are mixed. I was ...
Alexandra's user avatar
0 votes
1 answer
70 views

Why doesn't the time update?

I am making an arduino clock/alarm. I use an LCD screen to display the time. void loop(){ static unsigned long timing=micros(); if (mode == 0) {//mode 0 is when the time should show ...
shurup's user avatar
  • 300
6 votes
1 answer
1k views

Syncing/taking external clock for SPI on Arduino Due

I have an Arduino Due with a SAM3X8E chip and am trying to read SPI data from an external source that is communicating in SPI. I was able to get data by identifying specific bytes that are identifiers ...
wallenut's user avatar
2 votes
2 answers
5k views

How to update multiple outputs simultaneously

I need to update simultaneously all the outputs of a specific port. I am familiar with using micro-processors assembly language. After initializing a port (Data Direction Register), I can write to ...
Marla's user avatar
  • 600