Page 1 of 1
10uS Timer
Posted: Sun Feb 06, 2011 1:14 pm
by wayne millard
Hi to all
How can i make a timer interrupt run at a 10us rate so that i can generate times to the nearest 10us.
Thanks,
Wayne

Re: 10uS Timer
Posted: Sun Feb 06, 2011 1:44 pm
by medelec35
Hiya Wayne
10uS = 1/ 10x10-6 =100KHz
So depending on osc speed, you can use timer 0 or If not using PWM, timer 2 to generate interrupt at that speed (time)
You have a choice of selecting a slightly shorter int time then using format:
count = count + 1
count < a_number
then count = 0: Flag = 1 etc
Or you select a slower int frequency and add tmr0l += a_number; (or tmr0 depending on your target device).
If you want to post a flowchart that is set up for your target chip and osc speed + type of osc.
Then I will see if I can add the 10uS int macro.
10us is very quick, wont leave much time for anything else

Re: 10uS Timer
Posted: Sun Feb 06, 2011 1:54 pm
by wayne millard
Thanks medelec35,
I have not started the project yet just need to get the timer working first then start on the project.
any help would be very grateful.
Wayne
Re: 10uS Timer
Posted: Sun Feb 06, 2011 2:14 pm
by medelec35
If you let me know target device, osc type. internal external etc and speed. I will create one for you to work with.
Re: 10uS Timer
Posted: Sun Feb 06, 2011 2:24 pm
by wayne millard
medelec35,
I will use a 18F4520 and some thing like a 10Mhz clock.
Thanks
wayne

Re: 10uS Timer
Posted: Sun Feb 06, 2011 3:58 pm
by medelec35
Here is a version with a 10uS interrupt
Note the higher the osc frequency the better.
So I have enabled osc PLL x 4
Now with a 10MHz osc, the chip will be running a 10x4 = 40MHz
Re: 10uS Timer
Posted: Sun Feb 06, 2011 9:18 pm
by Harry Tuttle
Hi medelec35,
I have not seen ! used before (Output = !Output), can you explain it's function?
Thanks,
ben
Re: 10uS Timer
Posted: Sun Feb 06, 2011 9:58 pm
by medelec35
Harry Tuttle wrote:
(Output = !Output), can you explain it's function?
Thanks,
ben
Hiya Ben
I have used '=!' as a bitwise 'not equal to'.
So what it does is toggles the value of Output.
So If Output = 0 then after Output = !Output
Output will change to 1
If Output = 1 then after Output = !Output
Output will change to 0
etc.
So in this case was toggling port A0 every time interrupt was accessed.
I find it an easier method to learn than
Toggle = (Toggle XOR 0b11111111) AND 1
The 1 on the far right is the bit you want to toggle.
So if you want to toggle bit 3 you will need to use
Toggle = (Toggle XOR 0b11111111) AND 4
etc.