ckshivaram
Advanced Member level 6
- Joined
- Apr 21, 2008
- Messages
- 5,060
- Helped
- 2,150
- Reputation
- 4,306
- Reaction score
- 2,088
- Trophy points
- 1,403
- Location
- villingen (Germany) / Bangalore
- Activity points
- 30,088
Hi Romel,
The IR Sensor should be able to differentiate between a black and white surface if configured correctly.
I found the example project which uses your IR Sensor:
PIC18 Pulse Width Modulation (PWM) DC Motor Speed Controller with the RPM Counter Project
Have you double checked your connections and component values?
What are the distances from the test objects the IR Sensor output level transitions to high?
What type of objects have you used to test the IR Sensor?
BigDog
res = (res * 4.8)/1023 * 3.135;
void display_data(float res)
{
float ftemp1,ftemp2;
char ADC[2];
int temp1,temp2;
lcd_cmd(0xC0);
lcd_str("VOLT:");
lcd_cmd(0xC8);
res = (res * 4.8)/1023 * 3.135;
if(res < 10)
{
ftemp1 = (res * 100) / 100;
temp1 = (unsigned int)(ftemp1 * 10) % 10;
lcd_data(ftemp1+48);
lcd_data('.');
lcd_data(temp1+48);
if(r==1)
lcd_str(" ");
r = 0;
}
else
{
ftemp2 = (res * 100) / 100;
temp2 = (unsigned int)(ftemp2 * 10) % 10;
long_to_string(ftemp2,ADC,2);
lcd_str(ADC);
lcd_data('.');
lcd_data(temp2+48);
r = 1;
}
res = 0;
}
Very nice.
Did you end up using the mirrored reflective strip or something else?
BigDog
I have question.. I displayed the floating number of adc using this code..
is there any trick that I could display floating point from the result of this computation?
PHP:res = (res * 4.8)/1023 * 3.135;
bigdogguro said that I must avoid using float in 8bit MCU.. heheI declared res as float so that I can get the floating point... is there any other way of doing this?
I don't think you should use float variables, you can probably replace all the numbers with integers (using a multiplier)
also I don't think that long_to_string(ftemp2,ADC,2); will work correctly with a float
no it's not the same adc value below 10 will not display if I do that.. I dont know how I come up with this lines I just calculated manually then translate to program.. heheftemp1 = (res * 100) / 100; is the equivalent of ftemp1 = res;
res = (res * 4.8)/1023 * 3.135;
Actually I said you should avoid floating point arithmetic when possible.
There are several different techniques to confine your calculation to the use of only integers.
Integer math, scaler and fixed point are some of the most commonly used.
The following PDF demonstration the use of Integer and Scaler Math to calculate the voltage at an ADC channel:
ADC SCALER METHOD
Hope you find the method interesting,
BigDog
I just used the long_to_string to display the value above 9 and below 100 but my adc will just read up to 15v.
ftemp1 = (res * 100) / 100; is the equivalent of ftemp1 = res;
no it's not the same adc value below 10 will not display if I do that.. I dont know how I come up with this lines I just calculated manually then translate to program.. hehe
void display_data(float res)
{
char ADC[2];
int temp1,temp2;
lcd_cmd(0xC0);
lcd_str("VOLT:");
lcd_cmd(0xC8);
res = (res * 4.8)/1023 * 3.135;
if(res < 10)
{
temp1 = (unsigned int)(res * 10) % 10;
lcd_data(res+48);
lcd_data('.');
lcd_data(temp1+48);
if(r==1)
lcd_str(" ");
r = 0;
}
else
{
temp2 = (unsigned int)(res * 10) % 10;
long_to_string(res,ADC,2);
lcd_str(ADC);
lcd_data('.');
lcd_data(temp2+48);
r = 1;
}
res = 0;
}
See if you can put a slip of red color cellophane sheet between the transistor and the axle rotor .
All visible light will cutoff and sensor noise will reduce faulty /oversensitive detection.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?