Em 9/2/2011 10:23, Mohit (Lists) escreveu: > Isaac Marino Bavaresco wrote: >> Em 8/2/2011 22:27, Bob Blick escreveu: >> =20 >>> On Tue, 08 Feb 2011 23:47 +0000, "Wortinguk" wrote: >>> =20 >>>> I have a 16F88 project in need of advise. >>>> PWM output on CCP1 on RB0 drives a MOSFET to drive a motor. >>>> RB0/INT interrupt is enabled (on rising edge) >>>> The interrupt service routine does an adc sample of the current flowin= g >>>> to >>>> see if there is an overcurrent. (1 ohm resistor in ground side of MOSF= ET) >>>> This currently drives an LED if an overcurrent. >>>> >>>> But cant get my head around a method to tempory collapse the PWM outpu= t >>>> voltage if there is an over current condition and allow the PWM period= to >>>> continue and re-test the current in the next interrupt. Setting RB0 = =3D 0 >>>> wont >>>> do it. >>>> =20 >>> Hi Dave, >>> >>> A few things come to mind. I don't have the 16F88 datasheet in front of >>> me, so any of these could be wrong. But it is worth checking out: >>> >>> 1.Setting TRIS for the pin that PWM is coming out from. I think TRIS is >>> after the PWM circuitry so this might work. >>> 2.Setting TMR2 to some number higher than PR2 and stopping it. >>> 3.Setting CCPR1H to some number. >>> 4.AND-ing the PWM in hardware with the pin you are driving the LED from= .. >>> 5.Temporarily turning off PWM in CCP1CON. >>> 6.Setting PR2 to 0? Or does that only work on the next cycle? >>> >>> Cheers, >>> >>> Bob >>> =20 >> >> In an old project with PIC16F628, just turning off the CCP1CON left the= =20 >> pin at the last state set by the PWM controller. Sometimes it stopped at >> "1". To turn it off I needed also explicitly clearing the pin. >> >> Isaac >> >> __________________________________________________ >> Fale com seus amigos de gra=E7a com o novo Yahoo! Messenger=20 >> http://br.messenger.yahoo.com/=20 >> =20 > I usually pass a 0x00 duty cycle to the PWM module. > Then turn off Timer2 (or whatever timer is associated with PWM). > And then as a final measure, turn off the output pin. Writing 0 to the duty cycle will take effect only on the next cycle, CCPR1L is double buffered. If you can afford to let the current pulse to finish, then doing only this is enough and the simplest method to stop the pulses, unless you want completely turn off the PWM module. But if you need to stop the pulse immediately then more actions are needed. I'm not sure if your method is safe, because you are not turning off the PWM module (CCP1CON=3D0), and I think writing 0 to the pin in this situation may not work. Stopping the timer may left the PWM pulse stuck at some state. Isaac __________________________________________________ Fale com seus amigos de gra=E7a com o novo Yahoo! Messenger=20 http://br.messenger.yahoo.com/=20 --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .