Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

read PWM signal via PIC24F

Status
Not open for further replies.

Eng.Binomairah

Newbie level 6
Joined
Nov 22, 2009
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,363
I need to know about how i can read PWM signal via PIC24F
 

You mean you want to measure the duty cycle and frequency of a PWM signal?
If this is the purpose then you can do it very easily by configuring the capture module to capture the time between two consecutive rising or falling edges.This will give you the frequency of the PWM signal. The capturing of time between a rising and falling edge will give you the ON time of the signal. The ratio of the ON time to the Total Time (measured in the previous step) will give you the duty cycle of the signal.
Regards.
 
Very nice reply ..

Do u have an example code for that ?

Or a tutorial on that ?
 

Well i think that i have the code to measure the PWM frequency but i had written it for 16F877A chip. If that is of any help then i will send it to you. otherwise i will have to modify it.
Regards.
 

OK, can u send it to me ..

and if u could modify the code .. it will be much better

thanks
 

OK i will send it tomorrow. By the way what is the range of frequencies that you want to measure?
Regards.
 


Here is the code to measure the time period (frequency) of a signal using PIC24FJ64GA004. Try to understand it. Feel free to ask questions. Also try to refine it yourself because that is the only way you can learn programming. The zip file also has the simulation model for Proteus.
Regards.
 
i will read it and i will try to implement it to see how it is working ..

then i will tell u about the result

thanks alot man
 

350px-Dutycycle.png


i think your code will measure the period (Τ) not the pulse duration (τ)

where you are capturing the rise edge only so this will not give the result of the Pulse width ..

is it Right or i do not understand it correctly ?

also u set TimePeriod as int where u need to read float number ..

in the ConfigureIOs is this hardware configuration that i have to added or just internel hardware .. could u explain ?

the rest it seems ok untill now ..

so do we need to add another timer to caputre the falling edge as u wrote in the fisrt post :

waseem said:
If this is the purpose then you can do it very easily by configuring the capture module to capture the time between two consecutive rising or falling edges.This will give you the frequency of the PWM signal. The capturing of time between a rising and falling edge will give you the ON time of the signal. The ratio of the ON time to the Total Time (measured in the previous step) will give you the duty cycle of the signal.
Regards.


so is your code do this step or just showing only the rising edge as i understand..

really thanks for your help.. i appreciate that ..

Also if you need any help in other project .. i can help you ..
 

you got it write. I have also mentioned in my post that the code will measure the time period of a signal. You can also configure the module to measure the time between a rising and a falling edge (ON time of the signal). If you have the total time and the ON time of the signal then you can find the duty cycle of the signal. Because

DutyCycle=Ton/Total time(time period)


So you do not need an additional timer to measure the duty cycle.
I will try to modify the code so that you can get both the parameters. At the moment it is only measuring the time period (frequency) of the signal.
Regards.
Long Live Pakistan.
 

yes i understand you but the problem the period ON of the signal is not fixed..

so if we have the period of a signal and the period of ON signal we can get the period of the pulse easily ..

But in my case the period of the ON signal will vary .. as the resistance of the sensor vary the pulse will vary so i have also to capture the falling edge too..

Do u get my point ?

Thanks

Eng. Bin Omairah
 

This new code is measuring both the ON time of the signal and also the time period (frequency=1/TimePeriod). The code works like this
1. The module is configured to generate interrupt on every capture event.
2. Initially it is configured to capture the time on a rising edge.
3. Once the rising edge is detected and the time is captured. The module is
configured to capture the time on a falling edge(in the interrupt routine).
4. Once the falling edge is detected and the time is captured the module is
configured to capture the rising edge(in the interrupt routine).
5. Once the rising edge is detected and the time is captured the cycle is complete.
6. Capture1 variable holds the value of timer at rising edge.
7. Capture2 variable holds the value of the timer at falling edge.
8. Capture3 variable holds the value of the timer at the next rising edge.
9. TimePeriod=(Capture3-Capture1)/2.
10. ONTime=(Capture2-Capture1)/2.

Note this cycle keeps repeating.

And i think this is exactly what you want to do.
Regards.
 

sorry for the late reply ..

I could not test a code yet since i do not get the compenents of the circuit ..

i will get them by this Sunday ..

i will be testing the code next week...

thanks
 

You are welcome.No problem with the late reply. Wish you best of luck. In case of any problems feel free to ask. By the way you can simulate the code in Proteus software to understand the simple logic behind the code.
Regards.
 

Here is the code to measure the time period (frequency) of a signal using PIC24FJ64GA004. Try to understand it. Feel free to ask questions. Also try to refine it yourself because that is the only way you can learn programming. The zip file also has the simulation model for Proteus.
Regards.

I checked your code in Proteus but it is giving unexpected results.

For, 1Hz= time period=16960
2 Hz= 8480
3 Hz= 5653
4Hz=20624
5Hz=3392
6Hz=2826
7Hz=11785

For 7 and 4 Hz the output time period value seems to be wrong since as you increase the frequency time period should decrease.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top