PWM and Capture mode??

Status
Not open for further replies.

ChArLyZzZ

New Member
Hey guys
I'm connecting a DC motor to the CCP1 (PWM mode) and measring the RPM with a slotted wheel using a photo interrupter which is feedback to CCP2 (capture mode).
The math functions that i'm using work correctly and on a full speed the measured RPM matches the one given in the datasheet of the motor..
The problem is when i reduce the duty cycle of the motor, the measure RPM doesnt decrease,instead it increases a little bit!!!
I've found somewhere on the net that i cant connect a motor with a photo interrupter on the same PIC because of voltage supply disruption due to the fast switching of the PWM!
does anyone guys have an idea or build the same circuit before??
I really appreciate ur help
 
Hi friend,what do you think that have made people think they can't connect a motor with a photo interruptor on the same PIC?I think it's because they fear one of them will corrupt the other.Obviously it's the motor corrupting the photo interruptor.

Judging by the tune of the motor(or with the aid of a tachometer),did the RPM actually increase?You need to know it to determine whether the capture is working fine.If the RPM did increase while decreasing the duty cycle,then the photo interruptor could have no problem working with the motor,and you need to check the motor instead.

If the PWM generated voltage disruption did interfere with your photo interruptor,try reinforcing the isolation with optocouplers and better hardware to filter the supply for the photo interruptor.You can put anything together with a PIC as long as it makes sense.The only problem is how you get rid of the details.
 
One thing I can think of is that you are trying to do too much with the interrupts. (The pic cant finish one interrupt before another is called)
What values are we talking about for the RPM and PWM signals?
 
well here are the values:
crystal is 4 MHz
max RPM value of 5v DC motor is 10500 (datasheet)
Timer2: prescaler 16, postscaler 1
PWM: frequency = 5KHz => PR2 = 12
100% duty cycle => CCPR1L = 50

Timer1: Prescaler 8
Capture: every 16th rising edge
----------------------------------------------
According to my calculations,Timer1 should not overflow..
In my Interrupt service routine, i'm dividing the captured value by 16 as a first step, then using a 24 bit division to calculate the RPM and display it on LCD..at the end of ISR,i'm clearing the timer and the flags and restarting the same process
!!!!!
 
Since your calculation says the interrupt doesn't conflict with itself,then it's not quite likely to do it.I insist checking whether it's the RPM that has increased or it's the measurement that has gone wrong.The first step to determine the problem is essential.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…