Hi assembler code gurus, I have a short piece of asm for high speed PWM code, that currently takes 15 cycles. Preferably I would like it to be 12 cycles. :o) The PWM code must divide by 3, doing 2/3 the time at Current 2, and 1/3 of the time at current 1. At the moment it is 15 cycles total, 267 kHz. I would like 12 cycles, 333 kHz. This has been stumping me for an hour now, most annoying. My problem is that I need to check for any change in inputs on PORTA at some point during the 12 cycles. 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 and i'm moving 100+ mA out PORTB... So if anyone feels like a quickie challenge, can this 15 cycle code be reduced to 12 cycle code AND satisfy these: * must be 8/4 cycles PWM. * must have minimum 1 inst between write and read. :o) -Roman ;------------------------------------------------- ; 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) ; 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! 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) ;------------------------------------------------- -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads