Newbie remote control question?
Dear friends I have a remote control transmitter / receiver and I trying to convert the signal (1ms - 2ms) to a binary value and store in a variable eight-bit (BYTE) (0 to 255).:eek:
When using a potentiometer and converts a voltage is easy ... However I can not understand how to convert the pulse width!?
I need to multiply or divide a value to having the other binary value?? And store in variable?!?:confused:
I will use this value to control the speed of a small motor connected in (PORTC.2)... And the pulse is read in (PORTB.0)... PIC16F877 is used.
Look at the code I'm trying to use:
DEFINE OSC 10
DEFINE CCP1_REG PORTC ' Hpwm 1 pin port pin 17 rc2 ccp1
DEFINE CCP1_BIT 2 ' Hpwm 1 pin bit
ADCON1 = 2 ' Config. all porta as analog and porte as digital
TRISA = %11111111 ' Set all porta as input (analogs)
TRISB = %11111111 ' Set all portb as input
TRISC = %00000011 ' Set all portc as output except RC0 and RC1
TRISD = %00000000 ' Set all portd as output
TRISE = %00000000 ' Set all porte as output
rx_sp VAR PORTB.0 ‘ Pin port connected RX remote control
speed VAR BYTE ‘ My var to storage the pulse value ????????????
led1 VAR PORTD.0 ‘ Pin’s portD driving LED’s no used now:).
led2 VAR PORTD.1
led3 VAR PORTD.2
led4 VAR PORTD.3
my_pwm VAR BYTE ‘ Used to update value of (HPWM) ‘command…
start:
PULSIN rx_sp,1,speed
My_pwm = speed
HPWM 1,my_pwm,1000
GOTO start
END
Thanks for the help.