Ok, for awhile I had some real trouble with your code, but I think I have figured it out. I guess I have trouble doing 8 bit binary logic in my head. Plus IOR and XOR sometimes confuse me. Please check my comments within to see if I've got it. I will likely be converting this to a timer based system, based on a 28 or 40 pin PIC. This would give me enough pins for one or two 8 channel PWMs, and an 8 bit + control lines parallel port for input. The controller will likely be a 28 pin PIC that receives data via UART, and has an 8 bit data port common with all the slaves, and individiual control (address) lines. We'll see, I haven't figured out the control end quite yet. I will have to build in a failsafe so if one of the slaves freezes or dies, the controller doesn't sit in a loop waiting for a response. I figured on one line for a "Data Ready" and another one for "Request to Send". DR would be output from controller, and RTS would be input to controller. The controller would assert DR when it wanted to update the slave, then wait for the slave to assert RTS. Then the controller would put data on the bus, and either drop and reassert DR, or perhaps assert another pin. Then the slave would aknowledge transmission via RTS, and wait for the next value. The problem I see is that if the slave dies, the controller may sit in an endless loop waiting for a RTS from the slave. I hope that isn't too confusing. The other thing I was thinking is that if I switch to a 16f628, and a hacked up parallel comms between slave and master, I might be able to do some interesting stuff. If I don't care about PWM frequency, could I just run the PIC on the internal clock? Since PWM is more about a ratio between on and off, if I don't care about the total period, I should be able to get away with internal oscillator, and let it run however it wishes, right? As long as I plan the parallel comms with enough leeway for both extremes of course. Anyway, see comments in the code. Scott Dattalo wrote: (I'll use the abbreviated version of the code here to save space) > CLRW ;Build the bit mask for turning > ;off the PWM outputs. Assume that > ;all of the outputs will be turned > ;off. > ; > DECFSZ pwm0,F ;If the first counter has not reached 0 > IORLW 00000001b ;then we don't want to turn it off. > ; > DECFSZ pwm1,F ;Same for the second one > IORLW 00000010b ; Create a mask of all the bits on the PWM port that have had their counters expire. A 0 indicates an expired timer. > > ANDWF pwm_state,W ; Clear all of those pwm outputs > ;that have reached zero. AND the mask with the current state. If an output was 1 and the timer expired, you get 0, if it's 1 and the timer hasn't expired, you get a 1. So you end up with what the new state should be, assuming the main timer hasn't expired. > ; > XORLW 00000011b ;Toggle the current state. Basically invert the mask, 1 becomes 0, 0 becomes 1. > INCFSZ rising_edge,F ;If the rising edge counter has not > XORLW 00000011b ;rolled over then toggle them again. > ;Double toggle == no effect. However, > ;if the rising edge counter does roll > ;over then a single toggle will turn > ;the pwm bits on, unless of course the > ;pwm counter has just rolled over too. If the main timer has expired, then you accept the inverted state, if it has expired, you invert again, which ends up righting the output, and then you can copy it right to the port. *** What happens if you have a timer that expires while the mask was originally a 0? When you invert it the first time, it becomes a 1, which then would go and turn on the port. If it was a 1 though, then it becomes a 0, and the port is turned off. That should only occur if the value in the pwmX register was equal and in sync to the rising_edge main timer register. Does that mean that to have a PWM port off, you then need to reload the pwmX register with a 0x01 so it will time out immediately? Also, should there be a subroutine that runs after the main timer expires that will reload all the individual pwmX registers? > MOVWF pwm_state ;Save the state > MOVWF PWM_PORT ;update the outputs Ok, super long post, but comments truly appreciated. I am just trying to get my head around a lot of this. Thanks, Josh -- A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. -Douglas Adams -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics