> The only solutions I have require > reading PORTA directly after writing PORTB, which > I don't like as it is only 62nS between the two Where did you get this from. If I remember right (maybe I don't), output data is latched at the end of an instruction and input data is sampled at the start of an instruction. Therefore there is no time at all between the output from one instruction and the input received by the next. Your 62nS seems to be one Q cycle, but I thought there were 0 Q cycles between the two. Of course this doesn't apply if you're writing one port and reading from another. > ;------------------------------------------------- > ; PWM LOOP > ; (the 2 target currents were set previously) > > ; what this function does is spend 2 time units at current2, > ; and 1 time unit at current1. > ; actual is 10 cycles at current2 > ; and 5 cycles at current 1 > > ; this gives an average pwm current of 2/3 the way between > ; current2 and current1. > > ; pwm frequency is 267 kHz. (16MHz resonator) Switching to 20MHz would be the equivalent of running this loop at 12.8 instructions or 313KHz. > > ; also checks for any change in input pins in this loop! > ;------------------------------------------------- > pwm_loop > ; first output current1 to motor > movf current1,w ; get currents and phase switching > movwf PORTB ; send to motor! Why do you need such high PWM frequency if you are driving a mechanical system like a motor. Most motors don't "see" frequencies past 100Hz or so, certainly a motor will average 1KHz nicely. At 300KHz you're just increasing the RF harmonic content. Also, what are the bit values of CURRENT1 and CURRENT2? Are they only off by one bit, by all bits? > > nop ; > nop ; > nop ; (5 cycles) > > ;------------------------- > ; now output current2 > movf current2,w ; > movwf PORTB ; send to motor! > > nop ; let ports settle > nop ; + some delay > > ; now test input pins > movf PORTA,w ; get pin values from port > movwf inputs ; store in var > > xorwf inputs_last,w ; xor to compare new inputs with last values > skpnz > goto pwm_loop ; z, inputs not changed, so keep looping > ; (10 cycles) > ;------------------------------------------------- Why store the port A value to INPUTS? Can't the code after this loop fetch port A itself? ***************************************************************** Embed Inc, embedded system specialists in Littleton Massachusetts (978) 742-9014, http://www.embedinc.com -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads