Jump to content
IGNORED

bB Modulus?


pacgreg

Recommended Posts

Off the top of my head I can think of 3 options:

 

1) Use BCD for the variable that holds the cycle count. Then AND it with %00001111 and check if it is equal to 0 or 5. This option will use a few more CPU cycles than the other two, but is good if you absolutely must use mod 5 and don't have a lot of ROM space available.

 

2) Create a 45 byte lookup table with a 1 stored in every 5th byte and 0 in the rest. Then simply index into the lookup table with the cycle count variable and compare that value with 1. This option is good if you must use mod 5 and have more ROM space than CPU cycles.

 

3) Make it mod 4 or 8 (or any power of 2). Then you can simply AND the count variable with n-1 to obtain mod n quickly. This is the best option to use if you can tolerate using a value that is a power of 2. Ex: cycleCount AND %00000011 is equivalent to cycleCount % 4

Link to comment
Share on other sites

what else does the timer have to do?
do you really want 45 or do you want
0..44?

 count = count + 1
 if count = 68 then count = 0
 if count & 7 = 5 then count = count + 3

will go through a cycle with a length of
45

but it doesn't count 0..44

bits 0..2 count 0..4 and
bits 3..6 (ie count/8) count 0..8


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...