Jump to content

Recommended Posts

I am attempting to make an ohmmeter out of this chip by pulsing a pin using PWM. The pin has a resistor capacitor series network. The resistor is the unit under test. I can use tmr3 to get the time to reach a specific voltage level (1T = 0.63 x VDD) and can interrupt when the comparator trips, but how do I catch the start of the pulse? Is there an interrupt for pulse start or am I goign to need to feed the PWM signal into an external int? Or maybe one of you smart guys has a better way.

Any thoughts?

Share this post


Link to post
Share on other sites

Hi

You already have a timer associated with the PWM signal. Why don't you use it?.

The period signal is defined by a timer, things start when yes start the timer.

Use the comparator to stop it and read the value.

 

Another thing I'm not sure the PWM is the better tool for the job, because the becessary duty cycle to charge the capacitor is unknown.

 

HIH

 

Best regards

Jorge

 

Share this post


Link to post
Share on other sites

I am using the PWM, but a 50% duty cycle is what needs to be there due to the discharge of the capacitor after it charges. If I lengthen the DC, then the cap may not discharge enough for the next charge cycle and the timing will be messed up.

I also found out that the comparator interrupts on any change in the output. I dodn't know that up front, so I can use the discharge interrupt to setup for the next charge cycle.

I realize that I'm using tmr2 for the pwm, but there does not seem to be a good way of using that to catch the beginning of the pwm cycle. I have fed the pwm output into INT0 and this seems to work, but I suspect there is a better way. i don't understand how to use tmr2 to catch the pwm leading edge, but either way it will wind up being an interrupt, so whether a tmr2 or INT0 I guess doesn't really matter.

What do you think?

Share this post


Link to post
Share on other sites

Hi

 

2 hours ago, mityeltu said:

I realize that I'm using tmr2 for the pwm, but there does not seem to be a good way of using that to catch the beginning of the pwm cycle.

I think you are wrong here.

The beginning of the PWM cycle happens when TIMER2 is reseted  due to a match with PR2.

When Timer2 = PR2 a match interrupt is generated (TMR2IF). If you set the Timer2 postscaller to a 1:1 ratio, you will have this interrupt generated at the beginning of every PWM cycle.

 

HIH

 

Best regards

Jorge

 

Share this post


Link to post
Share on other sites

I'll have to check that tomorrow, but if I recall from the scope, I was not generating the interrupt on the positive edge of the pwm cycle. I'll check that tomorrow

Share this post


Link to post
Share on other sites

Hi

 

Check the figure 14-3 and 14-4 @ page 136 of the datasheet and cross-reference it with figure 12-1 @ page 126.

The TMR2/PR2 match signal that sets the PWM output to 1 also sets the TMR2IF interrupt flag to 1 via the TMR2 post-scaller.

 

HIH

 

Best regards

Jorge

 

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×