|
Forum Index : Microcontroller and PC projects : Reading a pin set to output???
| Author | Message | ||||
redrok![]() Senior Member Joined: 15/09/2014 Location: United StatesPosts: 209 |
Hi All: How can I read a pin set to output? It seems to say I can in the manual: " This function will also return the state of a pin configured as an output" ' Doesn't work I'm trying to read the state of a PWM pin forSetPin 24, DOUT SetPin 26, DOUT PWM 2,20,50 Pin(24) = Pin(26) ' Nore this SetPin 24, DOUT SetPin 26, DOUT PWM 2,20,50 A = Pin(26) Pin(24) = A use in a program. If I can't do it that way how can it be done? Thanks!! redrok |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3308 |
Telling us the chip that you are using, the error message and the error line would help. Assuming that you are using the 28-pin Micromite you cannot set pin 24 to anything because it is being used as a PWM output. Geoff Graham - http://geoffg.net |
||||
redrok![]() Senior Member Joined: 15/09/2014 Location: United StatesPosts: 209 |
Hi Geoffg;Yes, its an MX170 28pin uMITE mm.ver 5.0304 running on an "Explore 28". The Micromite User Manual MMBasic Ver 5.4 says: "This function will also return the state of a pin configured as an output." What is the meaning of this line in the manual? ' Doesn't work Yes, pin 26 is "in use" because it's a PWM-2A pin.SetPin 24, DOUT PWM 2,20,50 Pin(24) = Pin(26) Run [157] Pin(24) = Pin(26) Error: Pin 26 is in use However, its also an output. I also tried reading Pin 26 and putting it in a variable. ' Doesn't work So how can I read the output of PWM-2A?PWM 2,20,50 A = Pin(26) Run [161] A = Pin(26) Error: Pin 26 is in use BTW, these code snippets were just a test to determine why things didn't work. I actually wanted to directly read the state of the PWM as in the second snippet. redrok |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10570 |
A PWM pin isn't an output it is a PWM pin. AFAIK there is no way of reading the current status unless you can peek the relevant registers and even then it isn't obvious as you are trying to decipher which part of the timer duty-cycle you are in. Consider trying to interrogate whether an I2C pin was on or off - same issue. The fact that you have a slow PWM doesn't change the basic problem. A solution is to feed the PWM pin back into an input pin and read it. |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |