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.

How to capture PWM input w/o use of CCP module in DSPIC30f4011?

Status
Not open for further replies.

variaseng

New Member
Hi! Does anyone have any idea how to capture PWM input using a GPIO pin (w/o CCP module)? The thing I want to do is I want to monitor if the pin has a PWM input is going in it or not. And I need to monitor at the most 4 of these PWM inputs. Thanks very much for your help! :confused:
 
Since all you have to do is detect the presence or absence of a PWM signal (not measure it), use the "Change Notification" feature of the dsPIC. Set it up to detect a rising edge (or falling if you have it inverted) and then you will know when the PWM signal started. Your code would have a time-out period that would allow you to detect an absence of PWM if a change event didn't happen during a defined period of time.
 
Hi! Thank you very much for your reply. I have thought of using change notification feature, but I need to monitor 4 PWM inputs simultaneously. And as I've read, the CN inputs of dsPIC can only serve one interrupt even though there are at least 14 CN pins. Is there any other way I can do this by using only software? Thanks again! :)
 
After a CN interrupt fires, you would need to put your 30MIPS to use and check to see which pins changed (you have to store the previous state). This is no different than how you would approach interrupts on a PIC16F which has only 1 interrupt vector. If you were to do this in software only, you would have to poll your I/O pins all the time and wait for a change to happen. This would block other code from running on the controller. CN would eliminate the continuous polling making your code far more efficient.

The dsPIC30F4011 also has 3 external interrupts so you could map 3 signals to those and the last one on a CN pin.

Another option would be to use the timers on the PIC. All the timers support gated operation which means the timer would only count when the gate pin is asserted. If you combine that with the timer's period register, you could set it to interrupt after the PWM has been high for a defined period of time. You would have to periodically reset the timers to zero to eliminate any false triggers from noise or truncated PWM signals.
 
if you just need to know the PWM duty % and don't need to respond very quickly, you can just sample the PWM pin every X uS (like in any timer interrupt) and count how many times the pin is LO and how many times it is HI. That works because the int and PWM are at different frequencies and over time you must hit some of each state, some LO some HI.

So you could test it 100 times, then count how many times it is HI, and that gives you the PWM duty%.
 
The thing I want to do is to just check at least 4pins simultaneously whether there is a PWM signal going in that pin. Algorithm goes like this:

if(push_button)
check whether there is PWM on pin
if(PWM exists)
light LED

and

check whether PWM exists in pin 1 and 2
if(PWM exists on pin1 && PWM exists on pin2)
light LED

something like this. Thank you very much for the CN suggestion and for using one interrupt vector, I may try this. Timer gated operation is not possible for me, I think, since I will be limited to TxCK pins (which is only 2 for DSPIC30f4011).

Thank you very much again for your replies! :)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top