Skip to main content
deleted 184 characters in body
Source Link
ocrdu
  • 1.8k
  • 3
  • 12
  • 24

I am not sure if I am correct with my thinking, but I have no experience with Arduino so far, and I would like to generate a TTL signal using onean Arduino.

As far as I understand, a TTL signal is just a predefined controlled signal that repeats at a certain interval (e.g. 2 microsecμs).

An Arduino circuit arguably has a very fast clock (e.g. 16 MHz), so what I thought is I can basically just draw a square signal for whatever desirable interval (important to be down to the microsecond 10^-6).

So I used the following code, just choosing onea pin and changing its signal state between 0 and 1 and then using Serial.println to draw the signal out. Everything is inside a while loop that times everything to be generated exactly within 1 second.

#include <arduino-timer.h> // Variables unsigned long v = -1; int freq = 100.0; // Hz unsigned long d = floor(1.0/freq*1000000.0) ; // us Timer<1, micros> timer; // create a timer with 1 task and microsecond resolution void setup(){ unsigned long repeatEvery = 5000000; // Microseconds Serial.begin(9600); pinMode(3, OUTPUT); timer.every(repeatEvery, func1); // XXXXX microsec } void func1(){ unsigned long uSec = 1000000; // Microseconds (= 1 sec) PORTD = B00000000; v = digitalRead(3); unsigned long counter = 0, i = 0; auto currentTime = micros(); auto prevTime = currentTime; d = 0; // no delay to check the speed of the execution do{ PORTD = B00001000; v = digitalRead(3); // Serial.println(v); PORTD = B00001000; v = digitalRead(3); // Serial.println(v); delayMicroseconds(d); // first frame PORTD = B00000000; v = digitalRead(3); // Serial.println(v); PORTD = B00000000; v = digitalRead(3); // Serial.println(v); delayMicroseconds(d); // second frame currentTime = micros(); i = (unsigned long)(currentTime - prevTime); counter++; }while(i < uSec); Serial.print(">>>Counter:"); Serial.println(counter); Serial.print(">>>delay (ms):"); Serial.println(d); } void loop(){ timer.tick(); } 
#include <arduino-timer.h> // Variables unsigned long v = -1; int freq = 100.0; // Hz unsigned long d = floor(1.0/freq*1000000.0) ; // us Timer<1, micros> timer; // create a timer with 1 task and microsecond resolution void setup() { unsigned long repeatEvery = 5000000; // Microseconds Serial.begin(9600); pinMode(3, OUTPUT); timer.every(repeatEvery, func1); // XXXXX microsec } void func1() { unsigned long uSec = 1000000; // Microseconds (= 1 sec) PORTD = B00000000; v = digitalRead(3); unsigned long counter = 0, i = 0; auto currentTime = micros(); auto prevTime = currentTime; d = 0; // no delay to check the speed of the execution do { PORTD = B00001000; v = digitalRead(3); // Serial.println(v); PORTD = B00001000; v = digitalRead(3); // Serial.println(v); delayMicroseconds(d); // first frame PORTD = B00000000; v = digitalRead(3); // Serial.println(v); PORTD = B00000000; v = digitalRead(3); // Serial.println(v); delayMicroseconds(d); // second frame currentTime = micros(); i = (unsigned long)(currentTime - prevTime); counter++; } while(i < uSec); Serial.print(">>>Counter:"); Serial.println(counter); Serial.print(">>>delay (ms):"); Serial.println(d); } void loop() { timer.tick(); } 

The code above will give output as    counter = 47620 // how many times the instructions were repeated and if the Serial.println lines were uncommented so to draw the signal then the execution time gets so slowslows down to    counter = 86

I am not sure, if the whole train of thought is wrong and I should do something else or use a different circuit or not. Any

Any hint or help would be highly appreciated.

PS: my Arduino by the way is a UNIROIUNIROI that is supposed to be the same as Arduino R3an Arduino R3.

I am not sure if I am correct with my thinking, but I have no experience with Arduino so far, and I would like to generate a TTL signal using one.

As far as I understand, a TTL signal is just a predefined controlled signal that repeats at a certain interval (e.g. 2 microsec).

An Arduino circuit arguably has a very fast clock (e.g. 16 MHz), so what I thought is I can basically just draw a square signal for whatever desirable interval (important to be down to the microsecond 10^-6).

So I used the following code, just choosing one pin and changing its signal state between 0 and 1 and then using Serial.println to draw the signal out. Everything is inside a while loop that times everything to be generated exactly within 1 second

#include <arduino-timer.h> // Variables unsigned long v = -1; int freq = 100.0; // Hz unsigned long d = floor(1.0/freq*1000000.0) ; // us Timer<1, micros> timer; // create a timer with 1 task and microsecond resolution void setup(){ unsigned long repeatEvery = 5000000; // Microseconds Serial.begin(9600); pinMode(3, OUTPUT); timer.every(repeatEvery, func1); // XXXXX microsec } void func1(){ unsigned long uSec = 1000000; // Microseconds (= 1 sec) PORTD = B00000000; v = digitalRead(3); unsigned long counter = 0, i = 0; auto currentTime = micros(); auto prevTime = currentTime; d = 0; // no delay to check the speed of the execution do{ PORTD = B00001000; v = digitalRead(3); // Serial.println(v); PORTD = B00001000; v = digitalRead(3); // Serial.println(v); delayMicroseconds(d); // first frame PORTD = B00000000; v = digitalRead(3); // Serial.println(v); PORTD = B00000000; v = digitalRead(3); // Serial.println(v); delayMicroseconds(d); // second frame currentTime = micros(); i = (unsigned long)(currentTime - prevTime); counter++; }while(i < uSec); Serial.print(">>>Counter:"); Serial.println(counter); Serial.print(">>>delay (ms):"); Serial.println(d); } void loop(){ timer.tick(); } 

The code above will give output as  counter = 47620 // how many times the instructions were repeated and if the Serial.println lines were uncommented so to draw the signal then the execution time gets so slow down to  counter = 86

I am not sure, if the whole train of thought is wrong and I should do something else or use a different circuit or not. Any hint or help would be highly appreciated.

PS: my Arduino by the way is a UNIROI that is supposed to be the same as Arduino R3

I would like to generate a TTL signal using an Arduino.

As far as I understand, a TTL signal is just a predefined controlled signal that repeats at a certain interval (e.g. 2 μs).

An Arduino circuit arguably has a very fast clock (e.g. 16 MHz), so what I thought is I can basically just draw a square signal for whatever desirable interval (important to be down to the microsecond).

I used the following code, choosing a pin and changing its signal state between 0 and 1 and then using Serial.println to draw the signal out. Everything is inside a while loop that times everything to be generated exactly within 1 second.

#include <arduino-timer.h> // Variables unsigned long v = -1; int freq = 100.0; // Hz unsigned long d = floor(1.0/freq*1000000.0) ; // us Timer<1, micros> timer; // create a timer with 1 task and microsecond resolution void setup() { unsigned long repeatEvery = 5000000; // Microseconds Serial.begin(9600); pinMode(3, OUTPUT); timer.every(repeatEvery, func1); // XXXXX microsec } void func1() { unsigned long uSec = 1000000; // Microseconds (= 1 sec) PORTD = B00000000; v = digitalRead(3); unsigned long counter = 0, i = 0; auto currentTime = micros(); auto prevTime = currentTime; d = 0; // no delay to check the speed of the execution do { PORTD = B00001000; v = digitalRead(3); // Serial.println(v); PORTD = B00001000; v = digitalRead(3); // Serial.println(v); delayMicroseconds(d); // first frame PORTD = B00000000; v = digitalRead(3); // Serial.println(v); PORTD = B00000000; v = digitalRead(3); // Serial.println(v); delayMicroseconds(d); // second frame currentTime = micros(); i = (unsigned long)(currentTime - prevTime); counter++; } while(i < uSec); Serial.print(">>>Counter:"); Serial.println(counter); Serial.print(">>>delay (ms):"); Serial.println(d); } void loop() { timer.tick(); } 

The code above will give output as  counter = 47620 // how many times the instructions were repeated and if the Serial.println lines were uncommented to draw the signal then the execution time slows down to  counter = 86

I am not sure if the whole train of thought is wrong and I should do something else or use a different circuit.

Any hint or help would be highly appreciated.

PS: my Arduino by the way is a UNIROI that is supposed to be the same as an Arduino R3.

Post Reopened by VE7JRO, Juraj
Post Undeleted by Juraj
Post Deleted by wisdom
added 1570 characters in body
Added to review
Source Link

An Arduino circuit arguably has an extremelya very fast clock (e.g. 16 MHz), so what I thought is I can basically just draw a square signal for whatever desirable interval (important to be down to the microsecond 10^-6).

So I used the following code, just choosing one pin and changing its signal state between 0 and 1 and then using  Serial.println and one ofto draw the ports that changes between B00001000 and B00000000 (2 times each for a square signal), out. Everything is inside a while loop or such for one complete second (i.e. 1000 ms) and check how manythat times the circuit is ableeverything to repeat such instructions. However, that did not work as expected and I got a very small number of repetition inside abe generated exactly within 1-second while loop depending how many instructions I have inside e.g. with 4x second

#include <arduino-timer.h> // Variables unsigned long v = -1; int freq = 100.0; // Hz unsigned long d = floor(1.0/freq*1000000.0) ; // us Timer<1, micros> timer; // create a timer with 1 task and microsecond resolution void setup(){ unsigned long repeatEvery = 5000000; // Microseconds Serial.begin(9600); pinMode(3, OUTPUT); timer.every(repeatEvery, func1); // XXXXX microsec } void func1(){ unsigned long uSec = 1000000; // Microseconds (= 1 sec) PORTD = B00000000; v = digitalRead(3); unsigned long counter = 0, i = 0; auto currentTime = micros(); auto prevTime = currentTime; d = 0; // no delay to check the speed of the execution do{ PORTD = B00001000; v = digitalRead(3); // Serial.println(v); PORTD = B00001000; v = digitalRead(3); // Serial.println(v); delayMicroseconds(d); // first frame PORTD = B00000000; v = digitalRead(3); // Serial.println(v); PORTD = B00000000; v = digitalRead(3); // Serial.println(v); delayMicroseconds(d); // second frame currentTime = micros(); i = (unsigned long)(currentTime - prevTime); counter++; }while(i < uSec); Serial.print(">>>Counter:"); Serial.println(counter); Serial.print(">>>delay (ms):"); Serial.println(d); } void loop(){ timer.tick(); } 

The code above will give output as counter = 47620 // how many times the instructions were repeated and if the Serial.println command I got only 86 times, while when lines were uncommented so to draw the signal then the execution time gets so slow down to printlncounter = 86 being omitted I got 50016 times.

enter image description here

An Arduino circuit arguably has an extremely fast clock (e.g. 16 MHz), so what I thought is I can basically just draw a square signal, using  Serial.println and one of the ports that changes between B00001000 and B00000000 (2 times each for a square signal), inside a while loop or such for one complete second (i.e. 1000 ms) and check how many times the circuit is able to repeat such instructions. However, that did not work as expected and I got a very small number of repetition inside a 1-second while loop depending how many instructions I have inside e.g. with 4xSerial.println command I got only 86 times, while when println being omitted I got 50016 times.

An Arduino circuit arguably has a very fast clock (e.g. 16 MHz), so what I thought is I can basically just draw a square signal for whatever desirable interval (important to be down to the microsecond 10^-6).

So I used the following code, just choosing one pin and changing its signal state between 0 and 1 and then using Serial.println to draw the signal out. Everything is inside a while loop that times everything to be generated exactly within 1 second

#include <arduino-timer.h> // Variables unsigned long v = -1; int freq = 100.0; // Hz unsigned long d = floor(1.0/freq*1000000.0) ; // us Timer<1, micros> timer; // create a timer with 1 task and microsecond resolution void setup(){ unsigned long repeatEvery = 5000000; // Microseconds Serial.begin(9600); pinMode(3, OUTPUT); timer.every(repeatEvery, func1); // XXXXX microsec } void func1(){ unsigned long uSec = 1000000; // Microseconds (= 1 sec) PORTD = B00000000; v = digitalRead(3); unsigned long counter = 0, i = 0; auto currentTime = micros(); auto prevTime = currentTime; d = 0; // no delay to check the speed of the execution do{ PORTD = B00001000; v = digitalRead(3); // Serial.println(v); PORTD = B00001000; v = digitalRead(3); // Serial.println(v); delayMicroseconds(d); // first frame PORTD = B00000000; v = digitalRead(3); // Serial.println(v); PORTD = B00000000; v = digitalRead(3); // Serial.println(v); delayMicroseconds(d); // second frame currentTime = micros(); i = (unsigned long)(currentTime - prevTime); counter++; }while(i < uSec); Serial.print(">>>Counter:"); Serial.println(counter); Serial.print(">>>delay (ms):"); Serial.println(d); } void loop(){ timer.tick(); } 

The code above will give output as counter = 47620 // how many times the instructions were repeated and if the Serial.println lines were uncommented so to draw the signal then the execution time gets so slow down to counter = 86

enter image description here

Post Closed as "Needs details or clarity" by Greenonline, VE7JRO, jsotola
added 1 character in body
Source Link

I am not sure if I am correct with my thinking, but I have no experience with Arduino so far, and I would like to generate a TTL signal using one.

As far as I understand, a TTL signal is just a predefined controlled signal that repeats at a certain interval (e.g. 2 microsec).

An Arduino circuit arguably has an extremely fast clock (e.g. 16 MHz), so what I thought is I can basically just draw a square signal, using Serial.println and one of the ports that changes between B00001000 and B00000000 (2-time times each for a square signal), inside a while loop or such for one complete second (i.e. 1000 ms) and check how many times the circuit is able to repeat such instructions. However, that did not work as expected and I got a very small number of repetition inside a 1-second while loop depending how many instructions I have inside e.g. with 4xSerial.println command I got only 86 times, while when println being omitted I got 50016 times.

I am not sure, if the whole train of thought is wrong and I should do something else or use a different circuit or not. Any hint or help would be highly appreciated.

PS: my Arduino by the way is a UNIROI that is supposed to be the same as Arduino R3

I am not sure if I am correct with my thinking, but I have no experience with Arduino so far, and I would like to generate a TTL signal using one.

As far as I understand, a TTL signal is just a predefined controlled signal that repeats at a certain interval (e.g. 2 microsec).

An Arduino circuit arguably has an extremely fast clock (e.g. 16 MHz), so what I thought is I can basically just draw a square signal, using Serial.println and one of the ports that changes between B00001000 and B00000000 (2-time each for a square signal), inside a while loop or such for one complete second (i.e. 1000 ms) and check how many times the circuit is able to repeat such instructions. However, that did not work as expected and I got a very small number of repetition inside a 1-second while loop depending how many instructions I have inside e.g. with 4xSerial.println command I got only 86 times, while when println being omitted I got 50016 times.

I am not sure, if the whole train of thought is wrong and I should do something else or use a different circuit or not. Any hint or help would be highly appreciated.

PS: my Arduino by the way is a UNIROI that is supposed to be the same as Arduino R3

I am not sure if I am correct with my thinking, but I have no experience with Arduino so far, and I would like to generate a TTL signal using one.

As far as I understand, a TTL signal is just a predefined controlled signal that repeats at a certain interval (e.g. 2 microsec).

An Arduino circuit arguably has an extremely fast clock (e.g. 16 MHz), so what I thought is I can basically just draw a square signal, using Serial.println and one of the ports that changes between B00001000 and B00000000 (2 times each for a square signal), inside a while loop or such for one complete second (i.e. 1000 ms) and check how many times the circuit is able to repeat such instructions. However, that did not work as expected and I got a very small number of repetition inside a 1-second while loop depending how many instructions I have inside e.g. with 4xSerial.println command I got only 86 times, while when println being omitted I got 50016 times.

I am not sure, if the whole train of thought is wrong and I should do something else or use a different circuit or not. Any hint or help would be highly appreciated.

PS: my Arduino by the way is a UNIROI that is supposed to be the same as Arduino R3

Source Link
Loading