Searching \ for '[PIC]: PWM problems, HELP!' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=pwm
Search entire site for: 'PWM problems, HELP!'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: PWM problems, HELP!'
2001\02\07@132234 by Graham North

picon face
Hi, if you read my last post you will know that I am
controlling a motor in a pyrometer.

Well I have achieved a PWM output, but am having a few
problems.

I think the motor is 'sending' (right word?!) some noise
to the PIC, I have it running from a seperate supply, but
have had to tie the two grounds together because the FET
needs the source to be zero volts.  I have a diode connected
accross the motor, and decoupling caps everywhere! What
else can I do?

I have also written a piece of code that increases the
duty cycle with a switch press connected to PORTA,0 but
this does not work. I think it is switch bounce causing
this. Is there a way to debounce a switch in S/W? Or is
my code rubbish?

Main
       call    InitPorts
       call    InitPWM

Loop
       btfsc   PORTA,0         ; If switch is not pressed
       goto    Loop            ; don't worry

       movlw   B'00000001'
       addwf   CCPR1L

       goto Loop

This code does not take into account the CP1CON,5 and
CCP1CON,4 bits. Is there a way to increase the duty cycle
in this way, including these bits?

Well thats enough questions now, I hope someone can give
me some answers.

Thanks for your help,

Graham North
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

--
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


2001\02\07@161809 by Olin Lathrop

face picon face
> Is there a way to debounce a switch in S/W?

Lots of ways.  I usually end up with some sort of periodic interrupt anway,
usually every 1mS.  I have the interrupt routine check the input to be
debounced every clock tick, and set a software flag to the new state if the
input was the same some number of samples in a row.  I like to use 50mS for
the debounce time.  In other words, I don't consider the input as having
changed state until it has been the same for 50 consecutive samples at 1mS
per sample.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, spam_OUTolinTakeThisOuTspamembedinc.com, http://www.embedinc.com

--
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


2001\02\08@025322 by Vasile Surducan

flavicon
face
You may supply the motor and the pic from same supply ( if motor need
+5V ) but you must take care about connections. Physically you need to
conect the motor closer to the power supply and  after that the
pic chip. Also a great value capacitor (470-1000uF) must be connected near
motor on supply wires. It's better if a driver/isolator chip is included
between pic and fet transistors.

BUT AGAIN: Why chopped pyrometer ?

Vasile


On Wed, 7 Feb 2001, Graham North wrote:

{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\02\08@030200 by Vasile Surducan

flavicon
face
Olin, could you exemplify your valuable explanation with a piece of code ?
I'm interested how you check for 50 consecutive samples.
Thank's, Vasile

On Wed, 7 Feb 2001, Olin Lathrop wrote:

{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\02\08@071646 by Nebelong Bjarne

flavicon
face
Graham,
You might consider to test if the switch is released. In your code the Loop
will go on for ever if the switch is pressed. Meening the value in CCPR1L
will rapidly go from 0-1-2-...-254-255-0-...

Loop
       btfsc   PORTA,0         ; If switch is not pressed
       goto    Loop            ; don't worry

       movlw   B'00000001'
       addwf   CCPR1L

Loop2
       btfss   PORTA,0         ; Wait until released
       goto    Loop2            ; Loop

       goto Loop

This will not take care of bounces but I saw other answers on this.

Regards
Bjarne Nebelong

{Original Message removed}

2001\02\08@094511 by Olin Lathrop

face picon face
> > Lots of ways.  I usually end up with some sort of periodic interrupt
anway,
> > usually every 1mS.  I have the interrupt routine check the input to be
> > debounced every clock tick, and set a software flag to the new state if
the
> > input was the same some number of samples in a row.  I like to use 50mS
for
> > the debounce time.  In other words, I don't consider the input as having
> > changed state until it has been the same for 50 consecutive samples at
1mS
> > per sample.
>
> Olin, could you exemplify your valuable explanation with a piece of code ?
> I'm interested how you check for 50 consecutive samples.

I looked thru several of my projects that I know do debouncing, and was
surprised to find that they all had various but different wrinkles that
somewhat obscured the debouncing logic.  The most clear cut example I could
find is below.  Even so, this debounces a signal in one direction only, and
uses a 16 bit counter because the debounce time needed to be more than 255
mS.  For debouncing a pushbutton switch, you would want to debounce it in
both directions for about 50mS.  This code runs on a 16C923.

For whatever it's worth:

currdbc  res     2           ;mS over current must still be on for to be
valid

...

;
;********************
;
;   Timer 2 interrupt.  This interrupt occurs every millisecond and is the
;   basis for all timing in the system.
;

...

;
;   Check the over current sense input and set internal FLAG_OVCURR
;   appropriately.  FLAG_OVCURR is only set if the over current input
;   has been indicating an over current condition continuously for
;   TMO_OVCURR milliseconds.  Local 16 bit counter CURRDBC is the number
;   of milliseconds left that an over current condition must be indicated
;   for before FLAG_OVCURR is set.
;
        dbankif curr_reg
        btfss   curr_reg, curr_bit ;no instantaneous over current condition
?
        goto    ovcurr_on   ;over current condition is being asserted
        ;
        ;   The instantaneous over current condition is deasserted.
        ;
        dbankif gbankadr
        bcf     flag_ovcurr ;debounce over current is definitely false
        loadk16 currdbc, tmo_ovcurr ;reset over current debounce counter
        goto    done_ovcurr ;all done debouncing over current
        ;
        ;   The instantaneous over current condition is asserted.
        ;
ovcurr_on dbankis curr_reg
        bsf     flag_ovcurr ;init to sustained over current condition
detected
        dbankif gbankadr
        movf    currdbc+0, w ;make OR of all debounce counter bytes
        iorwf   currdbc+1, w
        skip_nz             ;debounce timeout not yet expired ?
        goto    done_ovcurr ;yes, FLAG_OVCURR already set

        bcf     flag_ovcurr ;sustained over current not yet detected
        movlw   1           ;get value to decrement debounce counter by
        subwf   currdbc+0   ;decrement debounce counter low byte
        skip_nborr          ;no borrow from high byte ?
        decf    currdbc+1   ;propagte the carry

done_ovcurr                  ;all done with over current debounce processing



*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, olinspamKILLspamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...