PDA

View Full Version : High End Pre with PIC 16F876A



abidr
- 28th April 2008, 07:16
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

mackrackit
- 28th April 2008, 07:33
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?

abidr
- 28th April 2008, 07:50
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

mackrackit
- 28th April 2008, 08:19
The count code would be something like this


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.

abidr
- 28th April 2008, 08:31
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.

mister_e
- 28th April 2008, 17:30
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.

abidr
- 29th April 2008, 08:19
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.

ronjodu
- 29th April 2008, 21:43
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.


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..

abidr
- 30th April 2008, 06:57
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

ronjodu
- 2nd May 2008, 03:59
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

abidr
- 8th May 2008, 08:13
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