High End Pre with PIC 16F876A


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2008
    Posts
    13

    Default High End Pre with PIC 16F876A

    Hi Guys:
    I am quite new to PIC Programming and I thought it would be an excellent place to learn about it at this forum.
    I have been working on this idea of developing a high end pre around PIC 16F876A, though as far as I could go the porject works fine as long as I use up, down and mute buttons.
    But I cannot figure out a way how to configure that input selection stage so that one button changes the input (a total of four inputs) and when it reaches input 4, any new press on button input shifts the input to "input 1". I use ULN2803 for driving relays.
    Appreciate if guys here could help me out.
    Abidr
    Attached Files Attached Files
    Last edited by abidr; - 28th April 2008 at 07:18.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Not sure what you are after
    so that one button changes the input
    but this may give you an idea. http://www.picbasic.co.uk/forum/showthread.php?t=8602

    Or maybe use "count" routine. every time the button is pressed the counter increases. If the count VAR is 1 do something. If count VAR is 2 do something else. If count VAR > 4 then count VAR = 0.
    Is that what you need?
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Apr 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    thanks "mackrackit"
    link is not helpful.
    Other part is that is VAR=0 then input is "IPOD" if input =2 etc.
    My issue is how to define variable "an exmaple will be of great help" and how to shift the command to ULN2803 again an example will help.
    Attached is picture of populated PCB of the project
    abidr
    Attached Images Attached Images  
    Last edited by abidr; - 28th April 2008 at 07:55.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    The count code would be something like this
    Code:
    Bcnt VAR BYTE ' variable for counting
    Button VAR PORT?.? 'PIN FOR BUTTON
    
    MAIN:
    IF Button = 1 then Bcnt = Bcnt + 1
    IF Bcnt > 4 then Bcnt =0
    IF Bcnt = 1 then GOSUB someplace1 ' after done at the gosub "return"
    IF Bcnt = 2 then GOSUB someplace2
    so on and so on
    That is the basics, you may need a debounce routine and pauses. Maybe some endifs and elses too.

    The sub routines would have something like
    HIGH PORT?.?
    This pin will be connected to the pin on the 2803 that you want to trigger.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Apr 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Thanks dave heres is the code:
    ACTIVATE_RELAY:

    LOW MUTE ' Activate MUTE

    select case RELAY

    case 1 : PORTD = %10000000
    PAUSE 500
    case 2 : PORTD = %01000000
    PAUSE 500
    case 3 : PORTD = %00100000
    PAUSE 500
    case 4 : PORTD = %00010000
    PAUSE 500
    end select

    GOSUB SHOW_INPUT
    HIGH MUTE
    IF RELAY_FLAG = 0 THEN GOTO MAIN

    RETURN

    SHOW_INPUT:

    select case RELAY

    case 1 : LCDOUT $FE, $C0,"DVD 5.1 "
    case 2 : LCDOUT $FE, $C0,"USB DAC1"
    case 3 : LCDOUT $FE, $C0,"USB DAC2"
    case 4 : LCDOUT $FE, $C0,"CD "
    end select
    RETURN
    Let me give it a try I guess it should work now.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    If you need to count how many time a button have been pressed, you may use RA4/T0CKI. really easy to setup and work really fine. The only thing you need to read/reset is TMR0 register.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Apr 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Attached is the PIC of populated Project PCB.
    I have decided to put the button at RB6 and debounce it, so that it could change between inputs.
    I have already posted the whole code along schematics.
    Appreciate if someone could suggest improvements in the code or better mark area where code should be changed.
    Attached Images Attached Images  

  8. #8
    Join Date
    Dec 2003
    Location
    Storrs, Ct.
    Posts
    91


    Did you find this post helpful? Yes | No

    Default Snippett of my own.

    I also use a 2803 for relay control but use a PGA2320 for volume control. This is very much a work in progress but here is a snippett of code I use to change inputs and outputs. My switches however are a webpage done with a Siteplayer.
    Code:
    switches:
          INTCON.7 = 0
          SerOut2 PORTC.6,SPbaud, [$00, $C7, $1E]       
          SerIn2 PORTC.7,SPbaud, 100, mainloop, [power,ipod,computer,mute,bookshelf,subwoofer,volup,voldown]'
          INTCON.7 = 1
          checkswitches = 0
          if power = 1 then 
               high relay6
               high relay5
               INTCON.7 = 0
               write 1, power
               INTCON.7 = 1
               gosub dostuff
               else 
               low relay6
               low relay5
               INTCON.7 = 0
               write 1, power
               INTCON.7 = 1
               endif
        return    
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
             'subroutine 
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    dostuff:
          mydata.0 = 0
          mydata.1 = ipod
          mydata.2 = computer
          mydata.3 = mute
          mydata.4 = bookshelf
          mydata.5 = subwoofer
          mydata.6 = volup
          mydata.7 = voldown
          select case mydata
                
                case 18
                     low relay1    'relays for speaker output
                     low relay2    'relays for speaker output
                     low relay7    'relays for Audio In
                     low relay8    'relays for Audio In
                
                case 20
                     low relay1   'relays for speaker output
                     low relay2   'relays for speaker output
                     high relay7    'relays for Audio In
                     high relay8    'relays for Audio In
                     
                
                case 34
                     high relay1    'relays for speaker output
                     high relay2    'relays for speaker output
                     low relay7   'relays for Audio In
                     low relay8   'relays for Audio In
                case 36
                     high relay1   'relays for speaker output
                     high relay2   'relays for speaker output
                     high relay7   'relays for Audio In
                     high relay8   'relays for Audio In
                case 82,84,98,100
                     volup = 0
                     INTCON.7 = 0
                     SerOut2 PORTC.6, 84, [$00,$81,$24,volup]
                     INTCON.7 = 1
                     gosub Increasegain
                     gosub Post_Gain
                     
                case 146,148,162,164         
                     voldown = 0
                     INTCON.7 = 0
                     SerOut2 PORTC.6, 84, [$00,$81,$25,voldown]
                     INTCON.7 = 1
                     gosub Decreasegain
                     gosub Post_Gain
                     
                end select
                INTCON.7 = 0
                write 2, ipod
                write 3, computer
                write 4, mute
                write 5, bookshelf
                write 6, subwoofer
                INTCON.7 = 1 
                return
    Done somewhat like yours. Hope this helps..
    "It will never happen here!" just happened here.
    My thoughts and prayers for Sandy Hook victims and families.

  9. #9
    Join Date
    Apr 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Rojodu:
    Thanks man for the help I think this code sample will be all that i need.
    Here is my updated version of preamp I call it V1.3.
    I guess this code will be enough.
    Check_sel
    If sel=0 then debounce_sel
    return
    debounce_sel:
    pauseus 200
    If sel=0 then check_sel
    relay=realy+1
    if relay=4 the relay=0
    return
    Abidr
    Attached Files Attached Files
    Last edited by abidr; - 30th April 2008 at 08:17.

  10. #10
    Join Date
    Dec 2003
    Location
    Storrs, Ct.
    Posts
    91


    Did you find this post helpful? Yes | No

    Default Your welcome.

    Glad you found it helpfull. Check out this thread for more reading and some pictures of my PGA and amp setup.

    http://www.picbasic.co.uk/forum/showthread.php?t=7717
    "It will never happen here!" just happened here.
    My thoughts and prayers for Sandy Hook victims and families.

  11. #11
    Join Date
    Apr 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Ok guys:
    Code completed sucessfuly, just needed a few tweaks here and there, it has compiled sucessfully and burnt to 16F876A well, now its testing (which I ll do over the weekend).
    Once completed I ll post my results here.
    Abidr

Similar Threads

  1. 16F883 and Problems with HIGH statement
    By aaanekre in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th October 2009, 01:09
  2. PIC keeps resetting when executing subroutine
    By jbirnsch in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 27th August 2009, 07:03
  3. Using Sleep
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th August 2008, 04:05
  4. need help simulating PS/2 mouse
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 9th December 2007, 21:49
  5. Pic suggestion for high precision voltage measure
    By d1camero in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 10th April 2004, 06:22

Members who have read this thread : 1

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