-->
Page 1 of 3

Using TOUT as analog input

PostPosted: Sun Oct 05, 2014 7:13 pm
by nitto
From what I have read PIN 6 / TOUT is a 10 bit 0v-1.1v analog input pin.
However after soldering directly to pin 6 on a couple of boards I have not seen any meaningful data using adc_read().

Sometimes I will get an expected result, for example wiring TOUT to ground will sometimes return 0 and wiring TOUT to pin 5 (1.1v) will occasionally give 1024.
However just as often these will return a random value (usually between 400 and 700) as it usually does when left floating.

adc.c does seem to include a few references to i2c and TOUT - I wonder if this was designed for a external i2c to ADC chip.

Anyone else had any success using TOUT as analog in?

Re: Using TOUT as analog input

PostPosted: Mon Oct 06, 2014 12:05 am
by nitto
Update:

I do get a reliable/correct value when restarting and calling adc_read() in user_init before at_init() and immediately after - however subsequent calls to adc_read() after user_init has completed seem to give bad data (and occasionally correct).

I am thinking something else depends on this ADC and needs to be disabled to take a proper reading.

More findings:

When calling adc_read() from inside at_cmd.c (at the final 'else') in a loop for 10 reads once every 250ms - I will occasionally get 10 valid results - however when it fails to read a proper value it returns the same result for each read:

at+;
not cmdlen -1
ADC value3: 67
ADC value3: 129
ADC value3: 43
ADC value3: 123
ADC value3: 40
ADC value3: 122
ADC value3: 39
ADC value3: 123
ADC value3: 38
ADC value3: 122
at_cmd error -1
at+;
not cmdlen -1
ADC value3: 1024
ADC value3: 1024
ADC value3: 1024
ADC value3: 1024
ADC value3: 1024
ADC value3: 1024
ADC value3: 1024
ADC value3: 1024
ADC value3: 1024
ADC value3: 1024
at_cmd error -1

Re: Using TOUT as analog input

PostPosted: Mon Oct 06, 2014 3:39 am
by igrr
nitto wrote:Update:

When calling adc_read() from inside at_cmd.c (at the final 'else') in a loop for 10 reads once every 250ms - I will occasionally get 10 valid results - however when it fails to read a proper value it returns the same result for each read:


I recall reading somewhere that ADC should only be used when the chip is not transmitting. It looks like you may be hitting periods when the radio is active. You may confirm that if you have an oscilloscope and an RF power meter — just set some GPIO pin high when doing adc, connect it to the scope, and correlate it with TX power level.

Would be nice to find a way to disable radio tx for a short period of time, btw.

edit: it was mentioned in this post: http://www.esp8266.com/viewtopic.php?p=527#p527

Re: Using TOUT as analog input

PostPosted: Mon Oct 06, 2014 7:01 am
by nitto
Thanks for that. I must have skimmed over that post.

I've tried a few functions to no avail:

rom_sar_init(); <-- seems to cause adc_read to always return 1024
wDev_DisableTransmit();
ppCheckTxIdle(); <-- seems to return 0 when valid data and 1 when invalid but not all of the time
ppMapWaitTxq(); <-- always returns 2
ppDequeueTxQ();