Hello, I'm wondering if its possible to make the led's alternate every 15milliseconds. I want to keep the PWM function that I still have for brightness. Also, can the arduino reliably delay or us millis as small as 0.0002 value? I wanna try to code 0.0002 delay between when the leds alternate
just to clarify, I only want #1 LED on for 15ms then a delay of 0.0002 before the #2 LED turns on for 15ms and so on. Can this be done with Arduino's code such as loop? Sorry, im still very new to this.
0.0002 seconds is 200 microseconds.
delayMicroseconds(200);
The fastest your eye can see is 17ms (17000us)
sorry, i should have clarified. 0.0002ms as in around 200 nanoseconds
Sure, but I doubt you will be able to see it.
Humens just see dimmed LEDs above a certain frequency.
millis are integers, they don't come with decimal places.
You can go to micros (1/1000th millisecond), but the shortest micros an Uno R3 does is 4us.
Leo..
oh i see now, that helps a lot. and 4us should be ok, i would have liked something around 1us. Im using an arduino nano, but i also have the uno r3.
Which Nano.
Nano is a generic name for a whole family of boards.
A classic Nano v3.0 is the same as an Uno.
Other Nanos could have faster processors.
Leo..
oh cool, yes i have the nano 3.0. so if i were to use a faster arduino and be able to use faster delays, what would happen if I used that same code in an arduino uno r3? would it have an error or just resort to the fastest its capable of doing?
Code will just continue when the delay has expired.
Anything smaller than 4micros will likely be treated as 4us.
You might be able to go a bit lower with low level code (advanched machine code).
Leo..
Who or what device will notice the LEDs?
Good question. What do dou want to achieve with that.
Ive been using a squarewave of 60hz with a decoupling capacitor in order to get a zero point square wave and then running it through an lm741 op-amp in order to get alternating +5v and -5v to drive a pair of transistors. This makes it so one transistor turns on and then the other every 60hz. These transistors allow PWM (from another source) to go through thus creating alternating PWM to turn on my gate drivers for the IGBT H-bridge. It works, but I feel like it could all be simplified with just two alternating outputs from the arduino. I use this homemade 10kw inverter to run my off grid appliances from 24VDC. The H-bridge goes into a big transformer and outputs 240Vac with split phase creating dual 120v as well. The reason for the nanosecond delay is for the deadtime between H-bridge switching to prevent shoot through. At the moment this is remedied with an R/C circuit. But nowadays, everything is timed within the software.
This has been done before, and is usually done with low-level (bare metal) code.
Enter some thing like "complimentary PWM with dead time" in the search box on top of this page.
Leo..
awesome, thank you. Ive been searching for days haha.
Please post the wiring of Your setup. Decoding Your words is not prefered.
im at work at the moment, but ill try to add some photos later. In reality I just want to alternate the two LED's (I have a picture of the arduino circuit at the top). Ive use an arduino in the past to drive a 1200A IGBT for a spot welder and it worked fantastic so I wanna try to power my DIY inverter with the arduino. The leds are the gate drivers basically, There is basically no wiring, The PWM outputs go straight to the drivers controlling the H-bridge. Really the only wiring are the four isolated 15v DC-DC modules for each gate driver.
You can run simple tests. Below code will show how much time a 328P processor takes for an analogWrite() at 16 MHz (Uno, classic Nano).
const uint8_t pinLed1 = 9;
const uint8_t potPin = A0;
void setup()
{
Serial.begin(115200);
pinMode(pinLed1, OUTPUT);
}
void loop()
{
int potVal = analogRead(potPin);
uint32_t startTime = micros();
analogWrite(pinLed1, potVal / 4);
Serial.println(micros() - startTime);
delay(1000);
}
The result is 8 (µs).
Both boards use the same 328P processor at 16MHz. Further it's simple to test. Compile your code for both processors and see if you get an error.
===
I'm not much of an electronic engineer but I would probably design a circuit like below; it might overlap with the search that @Wawa suggested.
The idea is that you can individually enable the LEDs by switching D2/D3. D2/D3 low and the LED is on if the PWM output is high, D2/D3 high and the LED is off regardless of the PWM output.
If you use direct port manipulation writing D2 or D3 high or low will take 62.5 ns.
To get to your fast delays you can search the web for arduino nop; a nop instruction (no operation) takes 62.5 ns so three nop instructions will get you close to 200 ns.
Question
Why do you use two analogRead statements?
thank you so much for all the advice, thats going to help a ton. When i get home im going to try and implement some of your code. switching the leds low and high is a much better idea. Although the least of my worries is the deadtime delay implementation at the moment. Ive already been able to utilize traditional R/C for that. But it would be cool to have it done in the software portion wich would allow quicker rise and fall times for the IGBT's gates without shoot through.
haha that was a quick test I did earlier to see if I can also get two different PWM modulation for each LED. I never got rid of the 2nd part of the code oops.

