Just got my first Arduino today (UNO), so my first project is to drive a led panel.
For this I need 9 outputs.
From what I see on the basic instructions, setting pinMode(blah, OUTPUT) should turn it into a digital output, which it does for 0,1,2,4,7,8,12 & 13). The other outputs (the ones marked with PWM) are outputting PWM. Clearly I must be doing something obvious as noone else seems to have this issue, and I couldn't find anything about it (other than how to make them work as PWM, not how to stop them doing it).
I have a program that just does:
void setup()
{
for(int i = 0; i < 14; i++)
pinMode(i, OUTPUT);
}
void loop()
{
while(1)
{
for(int led = 0; led < 14; led++)
{
for(int phase = 0; phase < 100; phase++)
{
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
}
}
}
}
which to my understanding should in turn pulse the digital outputs 100 times for each output. For all the pins that are not PWM, that is what happens. For the PWM pins it just puts a varying PWM pulse for about the time of the other outputs cycle.
What do I need to do to turn the PWM off and use them as a normal digital output please?
woodinblack:
which to my understanding should in turn pulse the digital outputs 100 times for each output. For all the pins that are not PWM, that is what happens. For the PWM pins it just puts a varying PWM pulse for about the time of the other outputs cycle.
How did you establish the part in bold?
woodinblack:
What do I need to do to turn the PWM off and use them as a normal digital output please?
woodinblack:
which to my understanding should in turn pulse the digital outputs 100 times for each output. For all the pins that are not PWM, that is what happens. For the PWM pins it just puts a varying PWM pulse for about the time of the other outputs cycle.
How did you establish the part in bold?
With an oscilloscope going through each pin. The non PWM pins look as expected, a series of 100 pulses that were about 4uS each, follow by a long gap, the PWM pins just have 1 full cycle about the same size of the the 100 pulses of the other pins.
They do but they are wired to the USB chip as well so you are bashing that up and down and you are driving two outputs together which is never good, and if you wire anything up to it then that can interfere with uploading code.
woodinblack:
the PWM pins just have 1 full cycle about the same size of the the 100 pulses of the other pins.
That's not what I would have expected. Since you're set up to test it, could you try putting a small delay after each digitalWrite to lengthen the pulse and see whether the pwm and non-pwm output pins then behave the same?
PeterH:
Since you're set up to test it, could you try putting a small delay after each digitalWrite to lengthen the pulse and see whether the pwm and non-pwm output pins then behave the same?
if I put a 3uS delay between the on and off, the PWM disappears. If I then upload the original code, it still isn't back. If I turn it off and on again with the original, it is back.
Very weird, but since putting a delay in it stops it happening, and the actual program I want to use has a lot more delays than that, it doesn't affect me much. It is still a puzzle, but not one that is going to cause me an issue, so I will just get on with fiddling with this thing
Yes it is a digital scope and I did think of that (I have an analogue one in the cupboard but it has 10 years of junk on it, assuming it still works!) as it is pretty low res (one of the velleman ones), but I noticed the effect before knowing their were PWM on those pins as I got the board yesterday, it was only when I was getting that waveform I noticed it was connected to the pins that had a little dash on them, then noticed the bit that said PWM.
I will see if I can drag the analogue scope out at some point and see if the effect is the same, although I have enough problems with my LED board so maybe it will be later than sooner!
No, sorry, a little confusion there, the original pins were not connected to anything, the leds I mentioned in my last post were in my next project that I was moving onto, and they were driven separately