Synchronous pulses


Results 1 to 17 of 17

Threaded View

  1. #7
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default

    Hi Andrew,

    Would you like me to describe one method for producing up to 8 precisely timed synchronous pulses (on a single port), each pulse with a pulse width value of from 0 (off) to 1023 usecs with 1 usec pulse width resolution? If so, please let me know and I'd be happy to explain how the following code snippets work. I apologize for the C code.

    Kind regards, Mike




    Code:
    unsigned int pulse[] = {  120,       // pulse 0 (RB0),  120-usecs
                               44,       // pulse 1 (RB1),   44-usecs
                               45,       // pulse 2 (RB2),   45-usecs
                             1001,       // pulse 3 (RB3), 1001-usecs
                                0,       // pulse 4 (RB4), off/not used
                                0,       // pulse 5 (RB5), off/not used
                                0,       // pulse 6 (RB6), off/not used
                                0 };     // pulse 7 (RB7), off/not used
    
    unsigned char toggle[1024] @0x400    // 1024 element (interval) toggle array
    Code:
    //
    //  1024 interval output routine (BoostC compiles the following
    //  do-while code into a 5-cycle loop which is perfect for 1-usec
    //  intervals with a 20-MHz clock).
    //
    void Output()
    { fsr0 = 0x400;                      // interval = 0
      do                                 // do
      { latb ^= postinc0;                // { latb ^= toggle[interval++]
      } while(fsr0h.3 == 0);             // } while(interval < 1024)
    }
    Code:
    //
    //  build new toggle array from the pulse array before calling Output()
    //
    void PrepArray()
    { for(i = 0; i < 1024; i++)          //
        toggle[i] = 0;                   // clear the array
      toggle[pulse[0]] |= 1;             // insert RB0 output toggle bit
      toggle[pulse[1]] |= 2;             // insert RB1 output toggle bit
      toggle[pulse[2]] |= 4;             // insert RB2 output toggle bit
      toggle[pulse[3]] |= 8;             // insert RB3 output toggle bit
      toggle[pulse[4]] |= 16;            // insert RB4 output toggle bit
      toggle[pulse[5]] |= 32;            // insert RB5 output toggle bit
      toggle[pulse[6]] |= 64;            // insert RB6 output toggle bit
      toggle[pulse[7]] |= 128;           // insert RB7 output toggle bit
      toggle[0] ^= 0xFF;                 // fix toggle[0] element
    }
    Last edited by Mike, K8LH; - 16th October 2009 at 21:57.

Similar Threads

  1. I Need Help.. I want to generate controlled pulses
    By alabbadi in forum PBP Wish List
    Replies: 7
    Last Post: - 18th November 2007, 10:42
  2. Count pulses between VARIABLE TIME
    By RodSTAR in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th October 2007, 12:44
  3. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  4. Timed pulses on 2 pins
    By Danie Joubert in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th March 2004, 07:38
  5. Counting pulses
    By srspinho in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 19th November 2003, 00:54

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