Timers perhaps?


Closed Thread
Results 1 to 13 of 13

Thread: Timers perhaps?

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    With the 1:16 prescale, you should have an output pulse at 244Hz (4mhz / 4 / 16 / 256 ), if my math is correct. And your portb.7 high pulse will only be 1us, maybe 2us. Disable the prescale, and you should get 3906.25Hz on the fast pin and if you rewrite the code to include the slow pin, you should get a bit slower than 1hz on the slow pin (just for testing of course). The way to speed this up is to preload tmr0 with a higher number to get the overflow interrupt to kick in faster. Problem with this is that once you get up to a certain point, you won't have enough left over cycles between interrupts to do anything useful, except jump and resume into and out of the interrupt routine. And I'm talking about using the Instant Interrupts method, not the PBP On Interrupt method. With the PBP On Interrupt method, you use even more cycles due to overhead when using PBP.

    And the tmr0=2 to correct for missed cycles? That won't correct for missed cycles, all that will do is reset tmr0 back to '2'. That 'missed cycle correction' is only used when you are preloading tmr0. So, say you want to preload tmr0 with 100, you'd actually load it with 102 since tmr0 will stop for a couple of cycles while it's being reloaded.

    If you're looking to update at 60hz to provide a visually pleasing effect, so you won't see a flicker, I really wouldn't worry about that until you get below about 30hz. When I'm messing with LEDs, I (or anybody I show my projects to or whatever it is I'm working on) can't really see a flicker down to about 25hz, and only then if I look at the LEDs at certain angles.

    But if you're hellbent on getting this to work (and I think it can work), you've got to get a fast PIC (40Mhz would be optimal, but the '648 is limited to around 20Mhz, might be fast enough, I'm just thinking an 18F series @ 40Mhz would give you the extra muscle to get the job done better and leave you more room to play with), make your code tight, and one the thing that'll help you out a bunch is to download and make use of those 'Instant Interrupts'. PBP's On Interrupt could be used to get the code working and debugged, then you could switch over to the other interrupt method, but I think you'd be better off with the Instant Interrupt's from the beginning.

  2. #2
    Join Date
    Aug 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    Forgive me if I'm wrong, but I think you might be missing something (or more likely I haven't explained it properly).

    I'll let you know how I think this works, and you can tell me where I'm missing the boat.

    With this code, Pin A.6/Clkout is putting out a 1Mhz stream.
    With the selected prescale, the interrupt will fire on every 4096 ticks of the main clock.
    When the interrupt fires, it sets port B.7 high, then low.

    Effectively, this gives me a 1Mhz signal on A.6, and a 244Hz signal on B.7.

    I'm not trying to generate the "fast" signal, as that's done by Clkout. I'm just trying to generate the "slow" signal.

    Do I have this right?

    My apologies for the poor explanations.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Doormatt View Post
    With this code, Pin A.6/Clkout is putting out a 1Mhz stream. With the selected prescale, the interrupt will fire on every 4096 ticks of the main clock. When the interrupt fires, it sets port B.7 high, then low. Effectively, this gives me a 1Mhz signal on A.6, and a 244Hz signal on B.7. I'm not trying to generate the "fast" signal, as that's done by Clkout. I'm just trying to generate the "slow" signal.
    Aha! You see, the problem is, you didn't tell me that you were going to use ClkOut for one of your pulse sources!
    Now this makes sense...
    Yes, this should work exactly as you describe.

  4. #4
    Join Date
    Aug 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    *Grin*

    Sorry! It was one of those cases of too much information trying to come out at once.

    Thank you again for working through this with me. It was greatly appreciated.

Similar Threads

  1. Timers
    By mitchf14 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th November 2008, 21:08
  2. Reading Timers
    By kevj in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th August 2007, 09:19
  3. hardware timers
    By Adam in forum General
    Replies: 3
    Last Post: - 7th March 2007, 01:10
  4. Availability of PIC timers from PBP
    By coda64 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th February 2006, 08:18
  5. Count Down Timers
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th October 2005, 18:34

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts