fantabulous68
Member
Is that your actual exact assigned project?.
yes. its my final design topic.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Is that your actual exact assigned project?.
yes. its my final design topic.
Doesnt IR travel way faster than you can measure?
specifications of design:
The design should be useful in liquid level or proximity detection. It should operate by detecting the distance from the target by reflection of an infra-red beam. It should safely detect the level of a liquid in a tank without any contact with the liquid itself. The device's range should be variable, from a couple of cm. to about 50 cm.
It is a continuous liquid level detector.
I must be able to display the results on an LCD screen.
ie. The level of the liquid in cm
tank empty
tank full
error message etc
The device should also be reconfigurable and able to work on any tank
well thats my plan.
while (1 == 1) // Do Forever
{
NOP();
for (i = 0; i < 3500; i++); // Delay 50 ms
NOP();
TMR2 = 0; // Setup for Sending IR Signal
TMR2IF = 0; // Reset TMR2 Interrupt Request Flag
T2CON = 0b01111100; // Enable TMR2 for 16 Cycles
TRISC5 = 0; // Output to IR LED
i = 0; // Look for Input Signals
while (!TMR2IF) // Wait for Completion of Output
if (0 == RC4)
i = i + 1; // Increment the Counter
TRISC5 = 1; // Finished, Turn Off Output
T2CON = 0b01111000; // Turn OFF TMR2
if (i > 15) // Signal Received
RC0 = 1; // LED On
else
RC0 = 0; // Nothing, LED Off
} // elihw
} // End cIR
You can do it you blink the IR led and count the blinks you get back.
the closer the water the less blinks you'll get back to count
Presumably you've never heard of the 'speed of light'?
Wikipedia says "299,792,458 metres per second", so in 1uS it travels 300m.
Wikipedia says "299,792,458 metres per second", so in 1uS it travels 300m.
Infrared (IR) radiation is electromagnetic radiation whose wavelength is longer than that of visible light (400-700 nm), but shorter than that of terahertz radiation (100 µm - 1 mm) and microwaves (~30,000 µm). Infrared radiation spans roughly three orders of magnitude (750 nm and 100 µm).
In physics, the speed of light is a fundamental physical constant, the speed at which light and all electromagnetic radiation travels in vacuum. It is usually denoted by the letter "c". In the International System of Units, the metre is defined so that c has the exact value of 299,792,458 metres per second.
Why's that? Got a diagram?
//////////////////////CALCULATING DISTANCE///////////////////////
void enable_interrupt(void)
//This function is basically designed to set the specific bits of the timer and capture registers
{
CCP1CON=0x05; //bits 3-0 of the capture control register are set to 0101.
//This mode is to capture every rising edge of the pulse being
//transmitted and then received
TMR1IF = 0; //The interrupt flag bit of the PIR1 register is cleared before
//enabling the interrupt.
CCP1IF = 0; //Before a capture is made, the Interrupt Request Flag bit
//CCP1IF of the PIR1 register is cleared.
CCP1IE = 1; //The capture interrupt enable bit is set to enable the interrupt
TMR1IE = 1;
//An interrupt will occur immediately provided that the GIE and PEIE bits of the INTCON
//register are set.
PEIE = 1;
GIE = 1;
}
void interrupt ISR(void)
{
if (TMR1IF) //if there is an overflow
{
TMR1IF = 0; //and the flag is then cleared
TMR1_OF++;
}
if (CCP1IF) //if there is a capture
{
CCP1IF = 0; //Zero Capture flag
if (Cap_1st) //allow only 1 capture to be taken
{
Cap_1st=0; //Cap_1st is cleared as if another value is captured before the previous value is read
//then the
t_capL=CCPR1L; //lower byte of the capture register
t_capH=CCPR1H; //higher byte of the capture register
capture_status=1; //signal that a capture occured is enabled.
}
}
}
void calc_distance(void)
{
long sample=0;
i=1; j=0;
Cap_1st = 1;
capture_status=0; //signal that a capture occured is disabled
TMR1ON = 0; //stop timer
//tH=TMR1H; tL=TMR1L;
tH=0; tL=0; t_capL=0; t_capH=0; //initialise capture
TMR1_OF=0;
Transmit40khz();
DelayUs(100);
enable_interrupt(); //Interrupt is enabled to capture time when the rising edge occurs
TMR1ON = 1; // start timer 1
//when timer 1 starts, the enable_interrupt function will be called to
//capture the time from the 40kHz signal once the first rising edge of the transmitted
//pulse occurs
//A continuous loop is run such that when the signal to state that a capture has occurred
// is 0, then the 40 kHz will be transmitted and received when sending out 10 pulses.
//Once this condition is satisfied, the global interrupt enable bit will be cleared to
//prevent the interrupt from occurring when an interruption is in progress.
//The timer is then stopped by disabling TMR1ON and TMR1IE.
while((capture_status==0)&&(TMR1_OF<1));
GIE = 0; //disable global interrupt
TMR1ON = 0; //stop timer 1
TMR1IE = 0; // disable timer 1 interrupts on overflow//
//Another condition arises such that if the signal to state that a capture has occurred
// is then enabled, then the sample time is calculated and stored in an array. The sample
// time is calculated via the difference between high byte of the capture time and the high
// byte of Timer1 added to the low byte of the capture time and the low byte of Timer1.
//The index is incremented. This then deduces the end of the function to get the samples.
//However, if the index is less than 20, then the function will continue.
if (capture_status==1)
{
sample = ((t_capH)*0x100)+(t_capL);
i = 2;
GIE=0; //Global interrupt is disabled to avoid another interrupt from occurring while
// an interrupt is taking place
t_capH = 0;
t_capL = 0;
}
if (i==1)
distance = 0;
//if and only if a capture is made will the process of distance calculation continue.
if (i==2)
{
time = sample * 1e-6; //since each count takes 1us to complete, this value is multiplied
//to the sample time.
//Distance is calculated via multiplying the time and distance light travels
//light travels 300m in 1 us.This result is divided by 2
//as speed travels twice the measured distance.
distance=(time*30000)/2; //[B]calculation in cm[/B]
//liquidLEVEL=heightOFtank-distance im still working on this part
}
return;
}
////////////////////END CALCULATING DISTANCE//////////////////////
How fast is your processor running, and how deep is your tank?.
1. OSCCON|=0x60; //set fosc to 4Mhz
2. I want to use a 50cm deep tank
It is a continuous level detetector.
Then do the maths - how long will it take light to travel 100cm?
1/300=0.003333333cm