Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PWM pulse width calculation

Status
Not open for further replies.

faysal_002299

New Member
I am a newbie. I am using dsPIC30F3011 for my purpose.

1. I need to calculate the Pulse Width (dutycycle) of a PWM signal. Please anyone tell me the ALGORITHM I should follow for this.
2. What should I use here for feeding the MCU with the - use external interrupt or input capture or change notification?

It would be great if anyone provide me some code samples for doing this.


with thanks,
Faysal
 
Is there any reason why you are using a dsPic rather than one of the simpler chips. The simpler chips are understood by lots of people and there are many examples of code available.

Using a dsPic is like learning to drive in a Formula 1 car. You will crash and burn.

Mike.
 
My main purpose is BLDC motor control, and handling some sensors data- that's why I am using dsPIC. Thanks for your quick reply.

Please help me to solve the problems I have cited in my post.
 
I am really in need of the anwer asap

Actually I dont have any problem with how to deal with BLDC motor with dsPIC. I just want to calculate the dutycycle of a PWM I am getting from a sensor. Please help me to find out the pulse width of the PWM- I am repeating my questions again:

1. I need to calculate the Pulse Width (dutycycle) of a PWM signal. Please anyone tell me the ALGORITHM I should follow for this.
2. What should I use here for feeding the MCU with the - use external interrupt or input capture or change notification?

waiting for a kind and effective reply
 
Last edited:
I'm assuming you want to measure the duty cycle of a pulse train?
For this, I would use the input capture mode. The dsPIC has a 4 word FIFO which should make capturing short pulses even easier. As for the algorithm:
%DutyCycle = hightime/(hightime + Lowtime)*100
 
How to get the actual time?

I'm assuming you want to measure the duty cycle of a pulse train?
For this, I would use the input capture mode. The dsPIC has a 4 word FIFO which should make capturing short pulses even easier. As for the algorithm:
%DutyCycle = hightime/(hightime + Lowtime)*100

Thanks for the answer. But how can I know the time (hightime or lowtime) inside the Interrupt Service Routine of input capture mode?

I assume that, I can use a timer for that purpose but how can I send this time information inside the ISR of input capture mode?

Please anyone tell me in detail as I am a beginner. I will be grateful if anyone provide me some code samples.

thanks in advance
 
But how can I know the time (hightime or lowtime) inside the Interrupt Service Routine of input capture mode?
I assume that, I can use a timer for that purpose but how can I send this time information inside the ISR of input capture mode?
The timer "values" are captured in the FIFO buffer (ICxBUF). You simply subtract one value from another to get the pulse width. If the PWM frequency is really high, I would recommend using two Input Capture modules since this will make the software simpler and less prone to error. You'd set one for rising edge and the other for falling edge and tie the two pins together.
Refer to the "dsPIC30F Family Reference Manual" more details on using the Input Capture modules.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top