DT interrupt/pulse generator


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    May 2007
    Location
    Suffolk, UK
    Posts
    59


    Did you find this post helpful? Yes | No

    Default

    Thanks Skimask

    The reload criteria seem to be right, as you also concur, but for the life of me I still can't understand why it is over 100 ticks out. I have measured the frequency both on a counter and on a scope so I think we can be pretty sure that's OK. I hope I can solve this rather than it just goes down as one of life's little mysteries.....!
    Thanks

    Adrian

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Adrian View Post
    Thanks Skimask

    The reload criteria seem to be right, as you also concur, but for the life of me I still can't understand why it is over 100 ticks out. I have measured the frequency both on a counter and on a scope so I think we can be pretty sure that's OK. I hope I can solve this rather than it just goes down as one of life's little mysteries.....!
    Thanks

    Adrian
    What do you mean by '100 ticks out'?
    Do you mean that it's over 100 ticks off of what you calculated to be the reload value?
    If that's the case, you might be forgetting about the overhead of the program itself (2 cycles to jump in, 2 cycles out, a couple of cycles to reload the timer itself, and so on)...
    Or something different?
    Maybe your 20Mhz is off?

  3. #3
    Join Date
    May 2007
    Location
    Suffolk, UK
    Posts
    59


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    What do you mean by '100 ticks out'?
    Do you mean that it's over 100 ticks off of what you calculated to be the reload value?
    If that's the case, you might be forgetting about the overhead of the program itself (2 cycles to jump in, 2 cycles out, a couple of cycles to reload the timer itself, and so on)...
    Or something different?
    Maybe your 20Mhz is off?
    Yes - that's what I meant. I imagined that the programme overhead would mop up 'some' 'ticks' but I was surprised when it ended up at 107 adrift. The oscillator frequency is a good point - I'll check that. At the end of the day I can adjust the programme to get the frequency as close as I need so I guess I shouldn't be too concerned

    Thanks for your input

    Adrian

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Adrian View Post
    I imagined that the programme overhead would mop up 'some' 'ticks' but I was surprised when it ended up at 107 adrift.
    You can count that out yourself. Just look at the .lst file, run thru the instructions manually and count them (branches, goto's, returns, retfie, all take 2 cycles, check the datasheet).
    If you know that number down to the exact cycle, you should be able to program in a specific frequency and check your oscillator frequency against that with a reasonable amount of accuracy.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Adrian,

    All latencies can be easily compensated for, by ADDING the reload value to the timer instead of just copying the value to the time.

    At the time the interrupt occurs, the value of the timer is 0, and it continues counting while the chip is doing what ever it has to do to get to the Handler.

    When it gets to the handler, and is ready to reload the timer, the timer already has an EXACT count of how long it took to get there. So when you ADD the const to the timer, it actually subtracts the time it took from the const and EVERYTHING is accounted for.

    Take a look at this page ...
    http://www.darreltaylor.com/DT_INTS-...rTemplate.html

    That program has everything you need, but at a minimum, check out the ReloadTMR1 routine which shows an easy 8 instruction cycle adding reload.

    hth,
    DT

  6. #6
    Join Date
    May 2007
    Location
    Suffolk, UK
    Posts
    59


    Did you find this post helpful? Yes | No

    Default

    Darrel

    Thank you very much. I have taken a look and 'instantly' it doesn't look so easy to understand, however it also appears to be very crafty and very useful. I am going to plug away at your code until it IS understood and then add this new-found knowledge to the ever increasing store of accumulated wisdom from all of you experts.

    Many thanks again to you for enlightening me and of course to Skimask for his valuable input

    Adrian

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I have taken a look and 'instantly' it doesn't look so easy to understand, ...
    It does look a bit confusing at first, but it couldn't be easier.
    A complete understanding of how it works will come later after getting it to work.

    This is really the only section you need to digest.
    Set Freq to 2000, Prescaler to 1, and T1CON to 0. Fill in the Main program and T1handler that gets called on each interrupt.

    Done deal.


    Code:
    ;--- Change these to match the desired interrupt frequency -------------------
    ;--- See http://DarrelTaylor.com/DT_INTS-14/TimerTemplate.html for more Info.
    @Freq       = 2000                ; Frequency of Interrupts in Hz
    @Prescaler  = 1                   ; Timers Prescaler setting
    T1CON = $00                       ; $00 = Prescaler 1:1, TMR1 OFF
    ; $00=1:1, $10=1:2, $20=1:4, $30=1:8 --  Must match @Prescaler value
    
    @ INT_ENABLE  TMR1_INT            ; enable Timer 1 interrupts
    GOSUB StartTimer                  ; Start the Timer
    
    ;____Your Main Program goes here______________________________________________
    Main:
      ;   ---- Your Main Program goes here ----
    GOTO Main
    
    ;____This routine is Called on each TMR1 Interrupt____________________________
    T1handler:
      ;   ---- Your interrupt routine goes here ----
      
    @ INT_RETURN
    DT

Similar Threads

  1. PTO Generator
    By b1arrk5 in forum Off Topic
    Replies: 7
    Last Post: - 25th November 2013, 14:25
  2. 2 Beam Optical Pulse Generator
    By WOZZY-2010 in forum Schematics
    Replies: 8
    Last Post: - 6th April 2010, 04:03
  3. DT instant interrupts with mister_e keypad
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th November 2008, 20:02
  4. Frequency Generator
    By ExYu in forum Off Topic
    Replies: 2
    Last Post: - 22nd January 2008, 18:25
  5. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 02:21

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