PDA

View Full Version : PIC 16F877A and RB out



mazoul72
- 24th August 2011, 13:48
Hello,

i want to command radio remote with jack rely to RBx
How make resistors system with different value to different voltage in remote ?
R2R voltage digital to analogic ?
or other method ?

Regards

mister_e
- 24th August 2011, 18:51
Hi and Welcome on the forum,
There's a couple of different approach you can use. Depending of the accuracy you may choose one of the following

1) A R2R network. So basically a couple of resistor attached to a single or multiple port then you mix them like a traditional OPAMP summing amplifier Like This (http://ikalogic.com/dac08.php)
2) PWM signal, then you filter with a low-pass filter. Usually a simple capacitor and op-amp buffer
3) Dedicated DAC chip. And still there, you have different flavor, 8,10,12 bits

Choice is yours.

mazoul72
- 24th August 2011, 18:55
Thanks.

What is the best method ?

i have another problem with program for conversion.
Hello,
i made this to programm ADC

bmf_comm1 VAR PORTB.0
bmf_comm2 VAR PORTB.1
'Variables
bmfsD VAR WORD
bmfs1D VAR WORD
iled var byte
blink1 var byte 'pour clignotement 1ère led
blink2 var byte 'pour clignotement 2ème led
'configuration du port pour lire l'entrée analogique
TRISA = %00000011 ' RA0 et RA1 en entrée
TRISB = %11111100 ' RB0 et RB1 en sortie
ADCON1 = $10000010 'RA0 à RA3

test_depart:
Low bmf_comm1
Low bmf_comm2
High bmf_comm1
high bmf_comm2
pause 2000
goto mainloop
'lecture de la valeur
getad:
PAUSEUS 50 ' Wait for A/D channel acquisition time
ADCON0.2 = 1 ' Start conversion
WHILE ADCON0.2 ' Wait for it to complete
WEND
Return

' Subroutine to get pot x value
getx:
ADCON0 = $41 ' Set A/D to Fosc/8, Channel 0, On
Gosub getad
bmfsD = ADRESL + (ADRESH*256)
Return

' Subroutine to get pot y value
gety:
ADCON0 = $49 ' Set A/D to Fosc/8, Channel 1, On
Gosub getad
bmfs1D = (ADRESH*256) + ADRESL
Return
val_leds:
low bmfs_comm1
low bmfs_comm2
gosub getx
gosub gety

if (bmfsD > 1000) Then Goto val_leds
if (bmfsD > 750) Then Goto boucle_led
if (bmfsD > 500) Then Goto boucle1_led
if (bmfsD > 250) Then Goto boucle2_led

High bmf_comm1
High bmf_comm2
pause 1500
goto val_leds
boucle_led:
iled = 0
while iled < 5
if iled = 1 or 3 or 5 then high blink1:low blink2
if iled = 0 or 2 or 4 then low blink1:high blink2
iled = iled + 1
pause 1000
wend
goto val_leds
boucle1_led:
High bmf_comm1
low bmf_comm2
pause 3000
goto val_leds
boucle2_led:
low bmf_comm1
high bmf_comm2
Goto val_leds
End

The leds works but always lightning , action on button (RB0 only for the moment) don't change anything.
No blinking ,no high , no low when i push different button
I don't know what .
thanks.

mister_e
- 24th August 2011, 19:10
There's no such thing as best method, all of them will work, the PWM one is the easiest but probably not the easiest one to predict the final value. R2R is also simple, but to get really good accuracy you need at least 1% resistor. The DAC is easy but usually not the cheaper method.

"How much accuracy you need" is the keyword I guess.

Forum Rule: Please, do not double post your code all over the place, I'v already reply to that in your second thread. ;)

mazoul72
- 25th August 2011, 17:49
I have +5 V on my jack input with car radio remote .
So i can't use a r2r (no voltage is possible , only resistor )

What is the method for it ?

Regards.

mister_e
- 25th August 2011, 18:04
Is there a Resistor chart or voltage chart available? Case not have you tried with a potentiometer? I mean if you tie a x Resistor to Vdd (or GND) it works?

If so, there's a thread in here made last week or so.

mazoul72
- 25th August 2011, 20:14
Normaly, it is a resistor , i tried with resistors .
There is already voltage in Jack female (behind radio)
It is a voltage with r2r ,not ?
a voltage +2v (for example) to +5v , is it right ?

mister_e
- 25th August 2011, 22:24
We can produce voltage with R2R or not. It really depend the way we code it. The previous link didn't but tied resistor to GND.

You need to know which resistor value you need for each function on the radio side. And next step, do you need to tie them between the jack and GND or between the jack and VDD (5Volts). High like ln between the jack and GND. The previous link show and explain how it works.

Next you just need to play on the remote/steering side. Follow my code, it read AN0 and AN1, then evaluate ONLY AN0 value and jump to some routines.