Let’s say the MCU is running at 4MHz. That’s a period of 250 nanoseconds. And every instruction cycle takes 4 periods. That’s 1 microsecond per instruction. If the programmer wants to make a delay of 5ns, that’s simple. Just execute the nop (no operation) instruction 5 times. But what if it’s 100ns or even 1 second? That’s where instructions like decfsz comes in. We can create longer delays by compounding a short section of delay. The idea is there but we need to manually calculate the number of times we should compound the short delay. That is why I wrote this program to simplify the calculation.
First and foremost, I should mention that I got the inspiration from a delay calculation program found on the Cytron website. The program was written by Kong Wai Weng in October 2004. I saw some improvements that have to be made so I wrote a new one myself.
The program is written in Visual Basic 2010 and should work fine on Windows 7, Vista or XP. For linux users, it will even run on Ubuntu or Debian with wine installed. The main highlight of my program is that the user can see the delay subroutine being generated and the program can copy the subroutine to the clipboard by just clicking a simple button. That way the programmer can paste it over at the MPLAB IDE without having to type the long subroutine code and substituting the values of d1, d2 and d3 manually.
For those wondering how the program works, basically the user have to use the trial and error approach. There are three values of d1, d2 and d3, so the user have to try and guess these numbers, and slowly adjusting them to match the delay duration they desire. I tried to write the program in a way that it can predict the values of d1, d2 and d3 but it will consume a lot of processing time as the computer have to try each possible combination of d1, d2 and d3. That’s 255 times 255 times 255 which is 16.6 million possibilities. And not to mention that it has to be run with a few decimal point so as to get a closer value (which will be rounded off in the end). I figured out the code but most of the time it just locks up the program because the process is just simply too long.
Finally, I hope the program is useful to you. To download it, click on the button below.
To show your support, ‘Like’ my website. If you’ve come across any bugs and errors while using the program, please inform me at email@example.com.