-->
Page 1 of 1

PWI input

PostPosted: Sat Sep 17, 2016 1:25 pm
by livetv
I'm wondering about the PWI option in the IO() function. What is it supposed to do? As I experimented, I found that grounding the pin gives me a 0 and raising it returns a 1023.

So I looked at source code and it appears that when you do an IO(PWI,pin) function, this does an analogRead() of a digital pin. It appears that the arduino implementation of analogRead() does not allow this but perhaps it provides a simulation by returning numbers in the range that the ADC would, just full low or full high.

My guess is that the analogRead() was used in ESPbasic code as a place holder until something like a pulse width detector could be implemented. Could this be? Is it likely to happen? Is there any other magic that I might be missing?

Re: PWI input

PostPosted: Sat Sep 17, 2016 1:45 pm
by PhilTilson
Like you, I can only speculate here!

I'm wondering if the idea is that it reads an analogue voltage which it then interprets as a percentage of Vdd, thus giving an approximation of the PWM ratio.

In other words, if it reads, say, 1.1 volts, it returns a PWM value of 33. This could be a simple way of interpreting a PWM signal. However, we really need to hear from the experts about this!

Phil

Re: PWI input

PostPosted: Sat Sep 17, 2016 11:26 pm
by Mmiscool
if you use pwo on a pin and you connect that pin to another that you do a pwi on you should receive the same value.

Re: PWI input

PostPosted: Sun Sep 25, 2016 1:08 am
by livetv
Well I tried it out and it does not work. I set a timer to report (through a handy meter) the value on pin 4 as I fed it a PWO from another pin. The only values I got were 0 and 1023 and when using 500 as a value in the PWO, I got a 1023 about half the time.

The IO(PWI,{pin}) function uses the analogRead() function in the Arduino library and I think that's where the problem is. I think we want to be implementing the pulseIn() function from the Arduino library. What I don't know is whether or not this needs an available and accurate interrupt or whether or not it is a blocking call with some kind of counter built in. It might be the former. Is there a limitation within the ESP8266 that prevents a precise interrupt on a pin and an accurate microsecond count?