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