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.

calculate duty cycle using pic mikrocontroller

Status
Not open for further replies.

eng_ibrahim

Member level 1
Joined
Nov 21, 2012
Messages
39
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,555
hello ,
i want to design a program using Mikro C on pic microcontroller to enter square wave to pic microcontroller and the microcontroller calculate the duty cycle of the input signal
thanks ,
 

duty cycle come from two time period : pulse high time / pulse period

pulse logic high is the time between a rising edge and next falling edge
pulse period is the time between two adjacent falling (or rising) edges.

you can measure these times using capture module or external interrupt + timer module
and simply calculate duty cycle
 
Use external interrupt. Set to detect risign edge when detected start timer and set to detect falling edge then when falling edge is detected make a copy of the timer value and then set to detect rising edge and when raising edge is detected stop timer and copy the timer value to another variable. From this calculate Ton and Toff of the signal. And based on that calculate the duty cycle.
 
Hello!
Use external interrupt. Set to detect risign edge when detected start timer and set to detect falling edge then when falling edge is detected make a copy of the timer value and then set to detect rising edge and when raising edge is detected stop timer and copy the timer value to another variable. From this calculate Ton and Toff of the signal. And based on that calculate the duty cycle.

Yes but this supposes that the microcontroller frequency is a lot higher than the signal you want to read.
Another method:
- Use a bit input for your signal
- Get the bit value at a fixed frequency. If the bit is 0, increment the value low, if it's 1, increment the value high.
- After a while, you can calculate the duty as high / (high + low).

Dora.
 
Hi,

As mentioned before: It depends on input signal:
* CMOS/TTL level?
* min frequency
* max frequency
* min duty cycle
* max duty cycle
* how fast the duty cycle changes

additionally:
* Your desired resolution,
* your desired accuracy.

(please use values: the calculator doesn´t understand "best possible resolution" ;-) )

Depending on your values:
* you may use the capture feature
* you may use the pin poll solution
* you may use an RC filter and the ADC (maybe combined with an analog switch)

Klaus
 
thanks a lot for your clarification but can any one give me an example using timer and capture input using Mikro C
thanks in advance
 

Hi.

Post#3..

We can give you the assistance...


Klaus
 

Which PIC are you using and what frequency Crystal ?
 

What will be your PWM signal frequency ?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top