khangzing
Full Member level 2
- Joined
- Feb 22, 2013
- Messages
- 123
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,298
- Activity points
- 2,148
Code:while(1) { generate_square(); // in 38 khz delay_ms(120); output_low(); // IR led in Off state delay_ms(380); // 380+120 = 500ms period }
- - - Updated - - -
use this procedure to generate square wave...
Now look at the recevier output oFF time that matters with distance.....
that can be found easily
- - - Updated - - -
Code:while(1) { for( i = 0 ; recieve == 0; i++) // Count for number of ms the output is low delay_ms(1); // i is the distance ouput may be for 1m i = 75; 1.5m i = 25; while(recieve == 1); }
- - - Updated - - -
They are not meant to change the duty cycle, They are meant to set a constant square wave for some time.....
#include <pic.h>
#define _XTAL_FREQ 20000000
//Timer0
//Prescaler 1:1; TMR0 Preload = 124; Actual Interrupt Time : 26.3 us
void init(void){
TRISD = 0X07;
TRISC = 0X00; //configure Rc2 as output for Emitter(pwm)
CCP1CON = 0X0C; //select PWM mode.
PR2 = 131; //Set period register for approx. 38khz.
CCPR1L = 65; //Set duty cycle for approx 50%
T2CON = 0X04; //Set timer2 pre/post scalers to 1 & start Timer2.
}
void main()
{
init();
int i;
while(1){
CCPR1L =0; //Set duty cycle for 0%
__delay_ms(380); //delay 380ms
CCPR1L = 65; //Set duty cycle for approx 50%
__delay_ms(120); //delay 120ms
this is my code...can u tell me how to proceed to get the distance as u said???