Hi Andrew,
The disadvantage of this particular method is that you need a PIC with lots of RAM, something like an 18F2620, for the 1024 byte toggle array. If this is a one-off project then perhaps that may not be a big deal.
The PrepArray() routine builds the following (abbreviated) toggle[] array from the pulse[] array values and the Output() routine uses those values to update LATB as shown below;
Code:
interval ^ LATB
0000-usecs toggle[ 0] = 0b00001111 0b00001111 RB3..RB0 toggled on
0001-usecs toggle[ 1] = 0b00000000 0b00001111
....
0043-usecs toggle[ 43] = 0b00000000 0b00001111
0044-usecs toggle[ 44] = 0b00000010 0b00001101 RB1 toggled off
0045-usecs toggle[ 45] = 0b00000100 0b00001001 RB2 toggled off
0046-usecs toggle[ 46] = 0b00000000 0b00001001
....
0119-usecs toggle[ 119] = 0b00000000 0b00001001
0120-usecs toggle[ 120] = 0b00000001 0b00001000 RB0 toggled off
0121-usecs toggle[ 121] = 0b00000000 0b00001000
....
1000-usecs toggle[1000] = 0b00000000 0b00001000
1001-usecs toggle[1001] = 0b00001000 0b00000000 RB3 toggled off
....

The advantage of using a "toggle" data array and XOR'ing the values with LATB over using an "output" data array and simply writing the values to LATB is that the "toggle" array only requires inserting eight "toggle" bits into the array. An "output" data array would require inserting many many "output" bits into the array.
The Do-While loop in the Output() routine compiles to the following 5-cycle instruction sequence (by the BoostC compiler) for perfect 1-usec intervals (with a 20-MHz clock);
Code:
loop:
movf _postinc0,W ;
xorwf _latb,F ;
btfss _fsr0h,3 ;
bra loop ;
In your program you would edit the pulse array values for the outputs and then call the PrepArray() routine to build the toggle array. Then I suspect you would wait for some "trigger" event before calling the Output() routine.
Any of this make sense Sir? I'm rather pressed for time and that tends to make my rushed explanations rather useless to most people. Sorry...
Regards, Mike
Bookmarks