I'm new to Arduino and trying to generate 4 periodic signals with 10us pulse width.
I have read some forums that show how to generate these pulses but they are not suitable for my case.
So here are my codes:
1. I think there are 4 separate signals on 4 DPins? What is the reference DPin? 2. I think they are continuous signals? Correct? 3. I think the ON-time is 10-us and OFF-time is 90-us. Correct? 4. The signals are displaced by 10-us from the previous one. Correct?
That might be due to the absolute accuracy of your Arduino clock frequency combined with the accuracy of your oscilloscope.
Does you Arduino have a crystal clock, or a ceramic resonator?
In fact your signal should be longer than the delay value because you don't take into account the time it takes to execute the bit manipulation lines.
I'm using Uno R3. Previously I was using digitalWrite but I noticed that was too slow for generating us-range signals. I also read some posts teaching how to generate PWM signals using Timer but I still don't know how to generate the displace between each signal.
When you wind up the time base on your scope so that your pulse covers over half of the screen and measure it again using the cursors, Do you still get the same pulse width. I suspect you will not, it will be a more accurate one.
As I understand it that only applies to the micros timer, this is a delay and it works as you would expect.
Yes, that's what I meant, the Arduino delayMicroseconds() function. Could probably do it with a hardware timer but I haven't had the need to learn AVR timers so far.
Excellent description. Yes -- ds1 is the reference.
All your required signals could be generated accurately and precisely using Timer Module(s) of the ATmega328P MCU of the UNO Board.
In the mean time you can have a look of the attached file for Timer/Counter Modules of the said MCU. Ch-10TCLec.pdf (443.2 KB)
And this says about micros() micro()
So you see the resolution you said only applies to the micros() timer, not the delay.
@jzz777
Note the page about the the delayMicro seconds says:-
This function works very accurately in the range 3 microseconds and up to 16383. We cannot assure that delayMicroseconds will perform precisely for smaller delay-times. Larger delay times may actually delay for an extremely brief time.
So it looks like you are using it in not the most accurate way.
One way round this might be to use the in line assembler and have a sequence of 16 nop operations.