Pule up, pulse down ...+ve & -ve pulses based around 2.5V


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie View Post
    A PIC can switch it's I/O in only a few uS - probably a lot faster than your Audio Chip can handle. You need to refer to the Datasheet of your Audio Chip to see how big or small those control pulses need to be.

    You pretty much got the code, except I would set the pin High or Low BEFORE setting the TRIS... Here's an example to send a 250uS Pulse...


    Code:
    	SoundUp con 1
    	SoundDown con 0
    	ChAVol var PortC.1
    	ChATris var TRISC.1
    
    ' Assumes ChATris=1 previously initialised...
    
    	'
    	' 	Subroutine Pulses Channel-A Sound UP
    	'	------------------------------------
    ChASoundUp:
    	ChAVol=SoundUp
    ChAPulse:
    	ChATris=0
    	PauseUS 250
    	ChATris=1
    	Return
    
    	'
    	' 	Subroutine Pulses Channel-A Sound DOWN
    	'	----------------------------------------
    ChASoundDown:
    	ChAVol=SoundDown
    	Goto ChAPulse
    If there is a minimum time BETWEEN consecutive pulses specified in the Datasheet, you may need a suitable PAUSE (or PauseUS) just before the RETURN statement.
    Many thanks Melanie - superb stuff (I didn't even know the PauseUS existed - fantastic!)

  2. #2
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    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?
    Last edited by HankMcSpank; - 26th October 2009 at 01:34.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    You're permanently in your vol_middle loop, which at the beginning sets the pin output HIGH. If you put a scope on that pin you would see it continuously pulsing between 5v and 2.5v. Instead of this...

    goto vol_middle
    finish:
    End

    Remove the goto vol_middle and end your program with...

    finish:
    Pause 100
    Goto Finish

    That way it will loop permanently at the finish point and your last vol_middle instruction of ChATris=1 (ie 2.5v) is what you will observe on the PICs pin.

  4. #4
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Thanks Melanie...that did it (my feeble excuse was that it was very late when I posted - UK time - & my brain was frazzled after a good few intensive hours at the bench) ...the ironic end to this little saga, is that having gotten the PIC to pulse that particular audio amplifier IC up & down - I'd overlooked that fact that the IC's digital volume control wasn't linear, but logarithmic (as all volume controls are - doh!) - & for my purposes, I actually need linear!

    Oh well, looks like a digital POT feeding an audio amplifier IC will now come firmly into focus!

    thanks once again Melanie - the bit you taught me about three levels from one pin will stand me in good stead for future circuits.

Similar Threads

  1. Pulse Capture and byte building
    By boroko in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st July 2009, 01:59
  2. Replies: 3
    Last Post: - 13th September 2008, 17:40
  3. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts