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

    Default DT interrupt/pulse generator

    I have used Darrel's interrupts to generate a 1KHz pulse stream. As I'm using TOGGLE the interrupts needs to be at a 2KHz rate. Using PicMultiCalc with 7 instructions and 20MHz oscillator this gives Timer reload as 63043. Using this I get 959 Hz. I have to load 63150 to get about 1,000Hz. 107 ticks seems a long way out to me. Can someone please tell me why the great discrepancy and/or what I'm doing wrong. Many thanks
    Adrian
    Attached Files Attached Files

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Adrian View Post
    I have used Darrel's interrupts to generate a 1KHz pulse stream. As I'm using TOGGLE the interrupts needs to be at a 2KHz rate. Using PicMultiCalc with 7 instructions and 20MHz oscillator this gives Timer reload as 63043. Using this I get 959 Hz. I have to load 63150 to get about 1,000Hz. 107 ticks seems a long way out to me. Can someone please tell me why the great discrepancy and/or what I'm doing wrong. Many thanks
    Adrian
    Looks about right to me...
    20Mhz oscillator = 5Mhz instruction rate/Timer increment rate
    5,000,000 / ( 65536-63043) = 2005 Hz
    5,000,000 / ( 65536-63150) = 2095 Hz

    Neither number above compensates for the 7 instructions, but the idea is the same.
    You've got the numbers right...or at least it looks like it.

  3. #3
    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

  4. #4
    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?

  5. #5
    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

  6. #6
    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.

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