You have to be a little bit careful with your assumptions about pins. On most Atmel parts from the ATmega group (used extensively for Arduino family products) a given pin can have multiple functions associated with it. It also has a default condition that lasts from power on until one of the peripherals that is associated with that pin is initialized. Once that peripheral is initialized it takes over control of the pin and excludes all other peripherals from having anything to do with the pin. It's kinda like a giant custody fight and there can only be one winner. what happens to the pin at that point depends on which peripheral prevailed. Tell me the processor, and the pin, and I'll try to tell what I think will happen according to the datasheet.If neither a high or low is sent to the pwm pin in the software is it in a high impedance state? Meaning it can not sink or source current. When I remove the low on the pin it must be in this high impedance state.
The microcontroller is an atmega 328. in the set up loop I declare pin 12 an output. If a certain condition is fulfilled at a sensor input(a>46) I write a low to the pin. Want to know the state of the pin if the condition is not fulfilled and no low is written to the pin. I am hoping then that pin 12 will be high impedance. If it was a high for instance it would damage the peripheral it was attached to and perhaps draw to much current from pin 12.You have to be a little bit careful with your assumptions about pins. On most Atmel parts from the ATmega group (used extensively for Arduino family products) a given pin can have multiple functions associated with it. It also has a default condition that lasts from power on until one of the peripherals that is associated with that pin is initialized. Once that peripheral is initialized it takes over control of the pin and excludes all other peripherals from having anything to do with the pin. It's kinda like a giant custody fight and there can only be one winner. what happens to the pin at that point depends on which peripheral prevailed. Tell me the processor, and the pin, and I'll try to tell what I think will happen according to the datasheet.
The datasheet for the ATmega328 will tell you how much current pin 12 can source. It is unusual for an "output" pin to be Low or High Impedance. I think what you have to do is switch it back and forth between and Output Low and an Input (High Impedance). I think it is unlikely that current from a GPIO pin will damage an external device. Check the datasheet in any case.The microcontroller is an atmega 328. in the set up loop I declare pin 12 an output. If a certain condition is fulfilled at a sensor input(a>46) I write a low to the pin. Want to know the state of the pin if the condition is not fulfilled and no low is written to the pin. I am hoping then that pin 12 will be high impedance. If it was a high for instance it would damage the peripheral it was attached to and perhaps draw to much current from pin 12.
In the Atmel architecture it is not clear to me if a pin is chosen as a PWM output, that the GPIO control registers have any effect at all over the pin. I think that if you want to make the pin an Input, you might have to find a way to trick the Output Compare/Input Capture peripheral into doing it in some fashion.Not sure if it is an answer to your problem, but what I have done in the past when using Picmicro's is when I want to leave the PWM controller running but disable the output, I simply make the port pin an input instead of output.
And reverse to allow the PWM output.
I just saw that it what @Papabravo has suggested also.
Max.
I originally did it on the advice of an App note, in my case the PWM output goes to the gate of a Mosfet which has a gate pull down resistor so it always turns off.It seems to me very wrong to switch an output pin into input (or hi-Z) mode while it's driving anything.
If the output is a PWM signal for instance, most likely the best way to "turn it off" would be to force it low, which on a PIC processor is easily done, just by setting a 0% duty cycle.
What ever works for you!In the case of PIC's the latter should reset the PWM at the end of the period. This is what I do.
This may depend on which PIC is being used, as peripherals on [perhaps newer?] PICs can take control of the TRIS. The UART, for example, once enabled is supposed to set TRIS without the programmer doing it.What ever works for you!
So far I have had no problem and it is very simple and after immediately returns to the programed PWM rate.
Max.
I could have been more specific. I am using 2 pwm output pins as you suggest. I am driving an opto-coupler. One of the outputs is coupled to the opto via a resistor. The other output is connected directly to the led in the opto. Then if the condition is satisfied on a sensor input of say AO> 50 a low is applied directly to the led which stops the opto turning on even if there is a high at the output of the other output pin. But for this to work properly when A0<50 the output of the direct connection to the led must be hi-Z. Is this what would happen? I may have to design a program to test this if nobody knows.It seems to me very wrong to switch an output pin into input (or hi-Z) mode while it's driving anything. If you do that, then the state that the external device sees would be undefined, which you have to assume causes the worst result--high, low, or oscillating--whatever you least want! Unless maybe you've got some sort of wire-or connection, where output A drives the load directly, and output B drives it via a resistor; then if A is active, it dominates, but if A is in hi-Z mode, B gets control. That's an unusual situation, though.
If the output is a PWM signal for instance, most likely the best way to "turn it off" would be to force it low, which on a PIC processor is easily done, just by setting a 0% duty cycle.
One was a small 12F683 and just "bsf TRISIO, GP2."This may depend on which PIC is being used, as peripherals on [perhaps newer?] PICs can take control of the TRIS. The UART, for example, once enabled is supposed to set TRIS without the programmer doing it.
Not sure if you can do the same with Arduino, never used it.But for this to work properly when A0<50 the output of the direct connection to the led must be hi-Z. Is this what would happen? I may have to design a program to test this if nobody knows.
Hi Max, I will write a small program to test what happens.One was a small 12F683 and just "bsf TRISIO, GP2."
Not sure if you can do the same with Arduino, never used it.
Max.
by Aaron Carman
by Jake Hertz
by Jake Hertz
by Duane Benson