Measuring duty cycle from pwm

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi

I want to retrieve information from an ADXL202 acc. sensor.
The ADXL displays the acc. with the duty cycle from an pwm output.
Since the acc. should be measured in a robot, there is not a big timeframe left over for this.
I know this is a beginner question, but on which port of an mega 8 should I put the output of the sensor and what would be a good strategy to measure the duty cycle?

Cheers
Rubi

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you have an ADC (channel) to spare? Then you could put a simple RC filter after the acc.sensor and measure the voltage. Other possibilities are to use an external interrupt or the input capture function of a 16 bit timer. Both consume quite some bandwidth depending how often you want to measure. Another approach is to use an 8 pin tinyAVR to do the conversion and communicate the data using SPI.

If you have a ADC channel left, I would go with that approach. Simple and easy.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

you can do this with the input capture pin of timer1 (ICP1) of the mega8
by using the input capture interrupt.

It is possible to configure the interrupt alternately for rising and falling
edges to measure the time between rising/falling and rising/rising edges with the captured value of timer1.

From these times you can calculate your duty cycle.

Regards,
Armin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would prefer the ADC, because i am using the ICP1 already,...
What values would you suggest for the R and the C ?
The frequency of the pwm is around 1kHz.

Cheers
Rubi

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The time constant of your RC should be at least ten times
greater than your frequency.

So 100k/100nF (= 10ms) would do the job.

Regards,
Armin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear Armin

Thanks alot , I will try this out today!

Cheers
Michael