Ok, it took me a while to get around to it, but I just had a chance to try this 'floating 2.5V...switchable to 5V or 0V' - it didn't work!
Here's the code (when the IC I'm driving - a TDA8551 - powers up, its digital volume control is at its lowest setting, so it needs to be initialised with 32 pulses - this being the halfway volume point)...
Code:
@MyConfig = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON
@MyConfig = MyConfig & _MCLRE_OFF & _BOR_OFF
@ __config MyConfig
DEFINE OSC 4
DEFINE DEBUG_REG PORTA
DEFINE DEBUG_BIT 0 ' RA0 = TX out to PICKit2 programmer USART tool
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 0 ' 1 = inverted, 0 = true
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 1 ' Set clock source Fosc/8 "2uS"
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
OSCCON = %01100000 ' 4MHz internal osc
ANSEL = %00000100 ' RA2 = A/D in, rest digital
ANSELH = 0
ADCON0 = %10001001 ' Right justify, channel AN2, A/D enabled
CM1CON0 = 0
CM2CON0 = 0
PORTA = %00000001 ' serial out pin idles high
TRISA = %00000100 ' RA2 in, rest out
TRISC=%00000010 -set all as output except portC1.1
SoundUp con 1
SoundDown con 0
ChAVol var PortC.1
ChATris var TRISC.1
counter var byte
counter = 0
vol_middle:
HIGH PortC.1 ‘ set port.C1 high
ChATris=0 ‘change portC.1 it to an output (2.5V-> 5V)
counter = counter +1
if counter > 31 then goto finish
Pause 1 'delay 1mS
ChATris=1 'Change PortC.1 back to an input (high impedance)
goto vol_middle
finish:
End
What I got was an initial 2.5V at startup (ie mid point between 2 x 330R resistors in series betrween 5V & ground - the junction connected to my port C.1) - then once pin C.1 was set to an output, the pin's level jumped to 5V as expected - all good , *but* it stayed there (at 5V). I'd thought that by setting pin C.1 back to an input, that the underlying 2.5V would return ....what have I done wrong?
Bookmarks