Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:42 11 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Reading a pin set to output???

Author Message
redrok

Senior Member

Joined: 15/09/2014
Location: United States
Posts: 209
Posted: 05:02am 27 Mar 2018
Copy link to clipboard 
Print this post

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
SetPin 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
I'm trying to read the state of a PWM pin for
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: Australia
Posts: 3308
Posted: 07:16am 27 Mar 2018
Copy link to clipboard 
Print this post

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 States
Posts: 209
Posted: 02:39pm 27 Mar 2018
Copy link to clipboard 
Print this post

Hi Geoffg;
  Geoffg said   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.
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
SetPin 24, DOUT
PWM 2,20,50
Pin(24) = Pin(26)
Run
[157] Pin(24) = Pin(26)
Error: Pin 26 is in use
Yes, pin 26 is "in use" because it's a PWM-2A pin.
However, its also an output.

I also tried reading Pin 26 and putting it in a variable.
' Doesn't work
PWM 2,20,50
A = Pin(26)
Run
[161] A = Pin(26)
Error: Pin 26 is in use
So how can I read the output of PWM-2A?
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 Kingdom
Posts: 10570
Posted: 04:27pm 27 Mar 2018
Copy link to clipboard 
Print this post

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.
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025