I have two separate strips of 24v white LEDs being lit using MOSFETs, each at 50% brightness using a 50% PWM duty cycle. They both turn on for a fraction of a second then both turn off, and repeat. But I want them to alternate such that when one is on, the other is off, and vice versa - both still driven at a 50% PWM duty cycle, just offset by half a cycle.
Any tips on how this can this can be achieved?
Any advice / thoughts would be very much appreciated - thanks!
I've got as far as this:
analogWrite(led_one, round(65535 * 0.5)); delayMicroseconds(1024); analogWrite(led_two, round(65535 * 0.5));
I need to use a 16-bit PWM resolution for reasons outside the scope of the question, but this is the reason for the 65535 * 0.5 duty cycle.
I calculated a 1024 microseconds delay because my microcontroller (a Teensy 3.1) has a PWM frequency of 488.28 Hz (see here - if I understand this correctly). That means the PWM period (cycle length) is 1 / 488.28 seconds. But I need half of that so that the second strip starts it's duty cycle midway through the first strip's cycle. That equates to a delay of 1024 microseconds.
To test this I used a special(ish) camera that seemed to show that the delay made no difference and both strips had the same PWM cycle start/end without the desired offset between them.
My assumption here is that a PWM duty cycle starts as soon as analogWrite() is called, and it starts at the beginning of the duty cycle. But maybe the function just applies PWM to that pin at some random point in the duty cycle predefined by a timing circuit somewhere else...