PIC Programming for Ultrasonic Sensor Help.

Status
Not open for further replies.

brightjoey

New Member
I'm having trouble understanding this particular phrase in this Ultrasonic Sensor PIC Programming guide pdf file in page 8 of 12.


Note - assumes a 20MHz crystal, which is 5MHz timer clock
// A 1:4 prescaler is used to give a 1.25MHz timer count (0.8uS per tick)

I assume it means the oscillator that is inserted in the PIC. But I still don't get "crystal" and the whole phrase. ><
 

Attachments

  • 救星.pdf
    701.4 KB · Views: 334
I'm having trouble understanding this particular phrase in this Ultrasonic Sensor PIC Programming guide pdf file in page 8 of 12.
I assume it means the oscillator that is inserted in the PIC. But I still don't get "crystal" and the whole phrase. ><

Hi,
The PIC divides the crystal frequency of 20mHz by 4 to give a 5mHz internal clock for the PIC.

A prescaler which is internal to the PIC can be programmed to divide by certain ratio's.
A 1:4 prescale will reduce the internal clock for use with say an internal Timer by 4, the system clock will still be 5mHz, but the Timer clock will be 1.25mHz.

A crystal or xtal is an external device that generates in conjunction with the PIC a 20mHz frequency, in this case.
 
Last edited:
Oh, so in normal English (a newb in electronics), crystal is something that controls the frequency, and the prescaler sets the timer clock(internal clock) lower than the main clock(system clock)?
 
1 More question


In the same datasheet in page 9 of 12. In the bolded fonts What does it mean when the range is divided into 72 and 185? The notes say its to convert to cm and inches respectively but I still don't get it?
 
In the same datasheet in page 9 of 12. In the bolded fonts What does it mean when the range is divided into 72 and 185? The notes say its to convert to cm and inches respectively but I still don't get it?

hi,
I don't use that particular programming language.

"range is divided into 72 and 185" its whether you want the displayed range in inches or centimetres

I cannot open your pdf,,???
 
i don't understand why 72 and 185 was need to convert to cms or inches?
is this no. is specific?


thanz for your co-operation.
 
i don't understand why 72 and 185 was need to convert to cms or inches?
is this no. is specific?


thanz for your co-operation.


hi,
IF the basic counting period of the range finder is 1 microsec , the time taken for sound to travel 1 mtr and back is approx 58 microsec.

But his design is set for a time count period of 0.8 microsec so 58/0.8 = 72 , so if he divides by 72 he gets the distance value in cms and if he divides the distance count by 185 he gets the distance in inches...OK.

BTW: these are the designers calculations, not mine!

There 2.54cms in 1 inch so 185/72 is an approximation....2.569!
 
Last edited:

In the bolded text, how did we get the 52ms delay?
 
Oo, is the 52ms set as default? Can we change the delay time?
Examples provided would be really helpful.

You could just count a number of TMR1 interrupts for a longer delay or pre load the TIMER1 counters with higher value for a shorter delay.
 
Does the crystal affect the value of the delay then?
And for example if I want it to have 100ms delay do I set "TMR1H = 100ms" instead of 0?
 
Does the crystal affect the value of the delay then?
And for example if I want it to have 100ms delay do I set "TMR1H = 100ms" instead of 0?

If you want ~100mSecdelay just count two of the TMR1 interrupts.
 
Oo..so the value of the range is keep until the next 52ms ?
During this delay time, can i able to show the range in LCD?
TQ again for your help
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…