Page 1 of 1
analogRead(gpio) for digital output (current pwm state?
Posted:
Mon Feb 01, 2016 2:08 pm
by gorec2005
Hi!
i look for method get current state for output gpio PWM-ed... similar "analogRead(gpio)" for analog input
via wire or direct via system (core) register's...
Re: analogRead(gpio) for digital output (current pwm state?
Posted:
Mon Feb 01, 2016 4:05 pm
by martinayotte
Do you means to read back the analog value of your analog output generated using PWM ?
Yes, you can, but you need first to filter out the PWM to make it a real steady analog output using resistor and capacitor, and secondo, you need to scale down the range so it can fit within the 0-1V range of the ADC.
Re: analogRead(gpio) for digital output (current pwm state?
Posted:
Tue Feb 02, 2016 2:06 pm
by gorec2005
martinayotte wrote:Do you means to read back the analog value of your analog output generated using PWM ?
Yes, you can, but you need first to filter out the PWM to make it a real steady analog output using resistor and capacitor, and secondo, you need to scale down the range so it can fit within the 0-1V range of the ADC.
I mean read back not analog value, but current digital PWM value from inside cpu (direct read from system register, or other similar ways)
Re: analogRead(gpio) for digital output (current pwm state?
Posted:
Tue Feb 02, 2016 2:17 pm
by martinayotte
Oh ! I see ...
If you wish to read back the values you've assigned in analogWrite(pin, value), they are stored into "uint16_t pwm_values[17]" locally in core_esp8266_wiring_pwm.c.
Unfortunately, there are no function yet to read them back, but you can easily write one in this file for your own purposes.