Hasan Malik
Junior Member level 1
- Joined
- May 26, 2012
- Messages
- 18
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,283
- Activity points
- 1,380
Can someone explain this comment of that code, how does timer0 one cycle calculated to be 4.352 cm>>???
//speed of sound 340m/s
//1 TMR0 cycle = (340/1000000)*256*0.5*100 = 4.352 in cm
#define TRIG PORTD.F0
#define ECHO PORTD.F1
double distance;
void main() {
TRISD.F0 = 1;
TRISD.F1 = 0;
TRISC=0;
OPTION_REG.T0CS = 0;
OPTION_REG.PSA = 0;
OPTION_REG.PS0 = 1;
OPTION_REG.PS1 = 1;
OPTION_REG.PS2 = 1;
while(1){
TRIG = 0;
delay_us(10000);
TRIG = 1;
delay_us(10);
TRIG = 0;
while(ECHO==0);
TMR0=0;
while(ECHO==1);
distance = (double)TMR0 * 4.352;
PORTC = (char)distance;//to check
Delay_ms(100);
}
}
//speed of sound 340m/s
//1 TMR0 cycle = (340/1000000)*256*0.5*100 = 4.352 in cm
#define TRIG PORTD.F0
#define ECHO PORTD.F1
double distance;
void main() {
TRISD.F0 = 1;
TRISD.F1 = 0;
TRISC=0;
OPTION_REG.T0CS = 0;
OPTION_REG.PSA = 0;
OPTION_REG.PS0 = 1;
OPTION_REG.PS1 = 1;
OPTION_REG.PS2 = 1;
while(1){
TRIG = 0;
delay_us(10000);
TRIG = 1;
delay_us(10);
TRIG = 0;
while(ECHO==0);
TMR0=0;
while(ECHO==1);
distance = (double)TMR0 * 4.352;
PORTC = (char)distance;//to check
Delay_ms(100);
}
}