Good evening,
i am using the following code in my Arduino Nano:
int l=128;
bool myArray[128] = {0};
void setup()
{
Serial.begin(250000);
pinMode(4, OUTPUT);
randomSeed(analogRead(0));
for (int j = 0; j < l; j++) {
if (j<10){
myArray[j]=1;
}
else {
myArray[j]=random(2);
}
}
for(int k = 0; k < l; k++)
{
Serial.print(myArray[k]);
}
}
void loop() {
noInterrupts();
while(true) {for (int i = 0; i < l; i++) {
bitWrite(PORTD, 4, myArray[i]);
}}
interrupts();
}
The idea is to change in a casual way (pseudo casual) the output voltage given by the digital Pin of the Arduino in a fast way, by sweeping the entries of the casual vector generated into the setup. However, when I watch the voltage output of my device using the oscilloscope in the persistence mode, I observe a small jitter between the different bits, like some bits are faster than other one. The duration difference is about100 ns.My question is: is my code that is not "good" enough or I am facing other problem not connected to that?
because I am stupid and I forget to change it after some quick test performed in order to see if the observed jitter is connected to that.
I will modify the original post. Thank for the observation
Sorry but I cannot provide a clarifying photo quickly, because I cannot use the oscilloscope now. How ever what I call jitter is a time variation of the edges of the bits of about 100 ns: considering a sequence of 10 bits, if I consider the 5th bit as example, I observe that the time position of the edges oscillates, with an amplitude of about 100 ns.
i am pretty new to the Arduino microprocessor, so, as I understand, the solution will be do all manually, am I correct?
leoneniko93:
Sorry but I cannot provide a clarifying photo quickly, because I cannot use the oscilloscope now. How ever what I call jitter is a time variation of the edges of the bits of about 100 ns: considering a sequence of 10 bits, if I consider the 5th bit as example, I observe that the time position of the edges oscillates, with an amplitude of about 100 ns. i am pretty new to the Arduino microprocessor, so, as I understand, the solution will be do all manually, am I correct?
Both edges, or just the trailing edge of each pulse?
Have you got the CRO triggering properly?
Thanks.. Tom..
Both edges Tom. The Cro trigger was set to trigger at each edges and in this way, I expect that the position of each edges will be in fixed if all is synced in the correct way.
I am monitoring directly the output of the Arduino, so I think cables are not the problem. I am trying to implement the code that you have suggested yesterday in order to see if the problem is connected to that.
leoneniko93:
Both edges Tom. The Cro trigger was set to trigger at each edges and in this way, I expect that the position of each edges will be in fixed if all is synced in the correct way.
How have you gt the trigger configured?
If both edges jittering, it sounds like you have not got stable triggering.
AC or DC coupled?
HF filter ON/OFF?
Pos or neg edge trigger?
Have to tried to adjust the trigger level?
I attack the oscilloscope photo of the channel in the persistence mode.
I am triggering to positive edges ( I have tried it in different level like 10% signal and 90% signal and in between )
The channel is DC coupled
Trigger optimized to high frequency
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Including where you are getting the trace from?
Can you just show us a single trace please, the persistence mode has basically over written what we need to see, a single sweep of your project.
Set your time-base so we see two or three pulses.
Is the point you have the scope connected to, driving anything?
Does it have a load?
Also a picture of your project so we can see your layout?
Any horizontal jitter will be due to your trace not being a clean squarewave, and the scope triggering on all the "ringing" on your signal.
Have you tried a simple HIGH/LOW output code to check your setup, or used a bit of PWM code just to verify your circuit?
Thanks.. Tom..
PS sending your images in jpg format will make easier for us to view.
1 & 2) I am observing with the oscilloscope directly the output voltage of the 4th digital pin. There isn't any other device connected to the Arduino. (the resonance showed in the other picture are due to the cable I used to connect to oscilloscope.)
5-8) I don't have anything except the Arduino Nano Board
9) Periodic signal (101010 etc): the difference between the output 0 and 1 is visible. That is the problem that act as jitter in my case I think. (the time duration of each pulse depend on the length of the vector l)
For l=2:
leoneniko93:
The idea is to change in a casual way (pseudo casual) the output voltage given by the digital Pin of the Arduino in a fast way, by sweeping the entries of the casual vector generated into the setup. However, when I watch the voltage output of my device using the oscilloscope in the persistence mode, I observe a small jitter between the different bits, like some bits are faster than other one. The duration difference is about100 ns.My question is: is my code that is not "good" enough or I am facing other problem not connected to that?
Every time round the while loop the timing will be different - you have two nested loops, the inner one will have a particular timing, the outer one its own timing.
Using hardware Timer1 on an Uno, I was able to get nice symmetric 1/0 pulses down to a pulse width of about 4.5 us. Any shorter than that and things fall apart. It appears the ISR can’t get the job done fast enough and you must wait for a full timer rollover (4 ms).
Might be able to shorten things even more with careful use of a “naked” ISR. But, this is a proof of concept and as much effort as I can put into it right now.
#include "Arduino.h"
const uint8_t logArraySize = 7;
const uint8_t arraySize = 1 << logArraySize;
const uint8_t arrayIndexMask = arraySize - 1;
const float pulseWidth = 4.5;
const uint16_t timerIncrement = pulseWidth * F_CPU / 1000000;
const uint16_t initialDelay = timerIncrement;
volatile uint8_t myArray[arraySize];
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("Starting");
PORTB &= ~(1 << PB1); // pin will be low when set for output
for (uint8_t i = 0; i < arraySize; i++) {
if (i < 10) {
myArray[i] = 1;
} else {
myArray[i] = random(2);
}
}
TIMSK0 = 0;
TCCR1B = 0; // stop counter, set waveform generator mode 0
TCCR1A = 1 << COM1A1; // waveform generator Mode 0, OC1A low on match
TCNT1 = 0; // reset counter
TCCR1C = 1 << FOC1A; // force OCR1A match
DDRB |= 1 << DDB1; // PB1 as output
OCR1A = initialDelay;
if (myArray[0]) { // Set next level on PB1
TCCR1A = (1 << COM1A1) | (1 << COM1A0);
} else {
TCCR1A = 1 << COM1A1;
}
TIFR1 = 1 << OCF1A; // clear interrupt flag
TIMSK1 = 1 << OCIE1A; // enable interrupt
TCCR1B = 1 << CS10; // start timer1 with pre-scaler = 1
}
void loop() {
}
ISR(TIMER1_COMPA_vect) {
static uint8_t arrayIndex = 0;
arrayIndex++; // next bit to send
arrayIndex &= arrayIndexMask;
OCR1A += timerIncrement; // set next compare A time
if (myArray[arrayIndex]) { // Set next level on PB1
TCCR1A = (1 << COM1A1) | (1 << COM1A0);
} else {
TCCR1A = 1 << COM1A1;
}
}
leoneniko93:
How ever what I call jitter is a time variation of the edges of the bits of about 100 ns: considering a sequence of 10 bits, if I consider the 5th bit as example, I observe that the time position of the edges oscillates, with an amplitude of about 100 ns.
Given that a single clock cycle of the 16 MHz ATMega328P processor lasts 62.5 ns, I think your expectations may be unrealistic.
Hi,
Is this just a look and see what you can get out of a Arduino controller, or is there an application you are going to use this in?
If it is just an exercise, then great, learning the limts of the controller is a good practice.
If it is for an application of some sort, you may need a faster controller, a DDS, direct digital synthesis IC.