> -----Original Message----- > From: PY2NI [SMTP:py2ni@UOL.COM.BR] > Sent: Thursday, February 21, 2002 12:10 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC]: Ultra fast low res PWM challenge > > Hi I did something like this, ages ago (Z-80, 8085 era). I just use > one > byte with a circular counter. You just have to rotate and output one > particular bit (B0 ie.). I couldn't find nothing faster than this, Z80 has > rotates os shifts, I don't remember now, where the carry bit don't > interfere > with operation, it makes the things even easier ( b0->b7 , b1 ->b2,.... > b7->b6). > You just have to perform the rotation and output a particular bit. > Hope > it helps. > > > Regards > Horta > Thanks for the tip, by coincidence I coded a rouine that does exactly that last night. clrf outport ; clear all output bits in the shadow register rrf pwm1,w ; put bit 0 into carry rrf pwm1,f ; rotate byte skpnc bsf outport,0 ; if carry set and set output bit rrf pwm2,w ; put bit 0 into carry rrf pwm2,f ; rotate byte skpnc bsf outport,1 ; if carry set, then set output bit movf outport ; update the PORT from the shadow reg movwf PORTB This is actually no faster than the original method, but has a couple of advantages, and one disadvantage. The disadvantage is that the duty cycle can no longer be set directly, you have to translate to a bit pattern which adds some overhead: setpwm: ; call with duty cycle in W. Need to add any bank switching, and limit maximum W!!! addwf PCL,f retlw b'00000000' retlw b'00000001' retlw b'00010001' retlw b'01001001' retlw b'01010101' retlw b'10110101' retlw b'11101101' retlw b'01111111' retlw b'11111111' To set a pwm channel you'd simply use the following which (I think) takes 8 cycles. movlw 5 call setpwm movwf pwm1 One advantage of this method is that one byte less RAM is needed (no PWM base counter), the other (possible) advantage is that the PWM frequency for mid range settings can be increased which can make filtering easier, or maybe reduce motor whine. This is quite a nice way to do things if you have the PWM running under an interrupt timer and it is not updated very frequently. Regards Mike -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads