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
}
Bookmarks