Hello. I'm trying to understand nigels delay routine (still new to pic's). Is some able to explain whats happening here in baby language for me please? its a 250ms delay routine, used in pulsing led's on and off.
why is decimal used at the beginning i.e. 250, and hex here?
I also don't understand "how" its creating a 250ms delay, and what needs to be changed to create longer, shorter delays. For example, wht needs to be changed to create a 100ms delay.........
This is actually a 1mS delay routine, generated by the online program on the PICList - I wrapped an extra counter (count1) round it, in order to have an adjustable routine, giving from 1 to 255mS.
Many of the delay routines in the tutorials have an extra entry point, DelayW - where it delays the number of milliseconds passed in W. They often also have a number of preset delay entry points, just to make life easy
I used a decimal number because it makes more sense, 250mS is a LOT clearer than 0xFAmS.
So total instruction cycles per call is
2*1 + 2*1 + 4 * 250 + 5*250*198 + 4*250 + 3*249 + 4*1 = 250255
Assuming you use a 4MHz oscillator, that's 1 MIPs(Million instructions per second). So each clock cycle lasts 1us. 250255 clock cycles take 250.255 ms.
The number of clock cycles taken by each instruction is given in the ref manual and datasheets under Instruction Set.
Thanks to you all. Im learning that delays are fundamental to PIC programming. If I wanted to use nigels delay routine, as posted above, yet, adjust certain values to achieve different delay durations, what are the values which should be changed??
Take for example, changing this 250ms delay, into a 175 ms delay routine?
Thanks to you all. Im learning that delays are fundamental to PIC programming. If I wanted to use nigels delay routine, as posted above, yet, adjust certain values to achieve different delay durations, what are the values which should be changed??
Take for example, changing this 250ms delay, into a 175 ms delay routine?
That's VERY easy (and explained in my previous post), the outer loop (which I wrote) executes the inner (1mS) delay 250 times - you just need to change the 250 to 175, this value is the delay time in mS.