Using analogWrite and getting strange initial results

@LarryD, the 2N7000s are NOT fully turned on. The DS voltage is ~2.5V (an estimate as my DVM is out of commission and I measured with an analog meter).

I have ordered some IRLML2502s and will have to redesign my PCB. While the circuit is working with the 2N7000s it does exhibit some unexpected behavior when mixing colors. Specifically when going for a pure white.

21 posts when I got here.... what kind of led strip?

Cause WS28xx led strips do not use PWM on power or data lines.

@GoForSmoke

A 12V common anode RGB strip. Fairly obvious from the posts that it’s not a WS28xx strip when you read all 21 posts.

Doesn't millis() already do that? The only time I use while() is when I deliberately want to block off a section of code, which is rare (at least for me).

Why not make up new variables for different "timeslices" ?

Note, I'm average Joe hobbyist and have never programmed professionally, ever. Read my two cents or don't if it's worthless to you. But every time I have used (and seen used) "beginTime" in the sense of a general non blocking clock against which all other time markers are compared, I have and have seen (which is why i have) it called as the first line of void loop() and never repeated.

It's always the other timers that get updated relative to that one millis() timer.

Hi, @djsfantasi

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

PLEASE do not try a cut and paste photo image or Fritzy.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

image.png

Unlabeled are the 10K resistors from the 2N7000 gates to ground. All ground connections are to the board’s ground plane.

Please ask for any clarification needed.

More info…

The large rectangle is an Arduino Nano. The two terminals labeled RXD and Com are for a future feature. The Nano ground and the 2N7000s are grounded to a ground plane.

Hi,
Bypass capacitor on the 12V input.
Some indicator LEDs for troubleshooting, on the power supply and each of the three outputs.
The LEDs for getting the project going, only the power LED needs to be fitted when final product made.

Tom... :smiley: :+1: :coffee: :australia:

@TomGeorge, thanks for your observations. My issue was a software rather than hardware problem.

I didn’t use a capacitor on the power input as there is already one on the Nano. As far as the LEDs, since the module is driving LEDs, they supply troubleshooting indicators. And the Nano also provides LEDs for power indication and other troubleshooting functions.

The wiring is very simple and repetitive. A GPIO pin goes to a MOSFET which drives LED(s). The only other component is a 10k resistor from Gate to Source to aid in shutting the MOSFET off. This is repeated three times. Not much to troubleshoot.

Arduino Forum

Doesn't millis() already do that? The only time I use while() is when I deliberately want to block off a section of code, which is rare (at least for me).

“Millis()” provides the value of the current time; “while” is a flow control construct. They serve different purposes. Combined they create multiple timers for multitasking.

My implementation of multitasking uses the general construct of

while ( now - begin comparison duration)

“Comparison” is either >= if we want to wait for a duration before executing the attached code block. Or <= if we want to execute the code block for a period of time specified by duration and then stop.

beginTime = millis(); // set beginning of next timeslice

Why not make up new variables for different "timeslices" ?

In fact, I do. There are two different timeslices in my sketch. The outer one defines the time over which I want to crossfade the LEDs. I use the variable loopBegin for that timeslice.

Within the outer timeslice, I need slices of time to perform individual steps of the crossfade. I use the variable beginTime for these timeslices.

Note, I'm average Joe hobbyist… But every time I have used (and seen used) "beginTime" in the sense of a general non blocking clock against which all other time markers are compared, I have and have seen (which is why i have) it called as the first line of void loop()and never repeated.

“beginTime” is just a variable name. I could have called it startTime, beginLoop, startLoop, loopBegin or foo. You may have seen it used differently but in that program that’s the name the programmer chose.

So now you have seen it used differently.

Okay, but I would still be putting at least a 0.1uF on the PCB.
LEDs on the PCB means you do not have to connect the strips up to do testing.
Saves on clutter while debugging, setting up.
Leave them off when getting to final product.

Tom... :smiley: :+1: :coffee: :australia: