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.

TMR2 interrupt and PWM sync

Status
Not open for further replies.

Mosaic

Well-Known Member
Is it reasonable to say that in a 16F886 when the TMR2 interrupt hits (PR2=255) the PWM cycle also starts?
Thus in order to ADC sample a PWM switched peak current pulse the minimum PWM DC must exceed the time for the ADC to be completed in the interrupt code?
So if the ADC sample needs 48 TMR2 ticks to complete, the minimum PWM is 48 (out of 1024).

All good?
 
Just to be clear!!! This is nothing to do with the special trigger???

But yes... When TMR2 matches PR2 the cycle starts... When TMR2 matches CCPR1H + CCP1CON bits 3 and 4 The the cycle flips... BUT!! all this depends on the pre-scale, you may well have 1024 resolution but it wont be 1024 ticks unless you have a pre-scale of 1:1..
 
So you are saying your total ADC conversion time is 48 ticks??.... What is the measurement... I take it the PWM is creating a current and you are monitoring said current as a feedback.... Will peak current be at the beginning of the cycle or towards the end?
 
The PWM is pulsing a current load.
The interrupt based ADC sample completes by TMR2 = 48 ticks. So what i am expecting is the PWM goes active from TMR2=0 thru to whatever the DC is up to TMR2 = 255. So I figure in order to know the peak current I must sample the current draw while the pulse is active and then use the PWM DC% to prorate the average current.
I need both instant and average values.

Since the PWM is running at 10bits.... that means 1024 slices of a 2048 uS time or 2uS per DC single step. Now since TMR2 rollsover in 2048uS => 8uS per TMR2 tick.
So a Tmr2 value of 48 =>384 uS. Wouldn't this correspond to a 10bit PWM value of 192?
 
Last edited:
You will have a minimum PWM high.... I would have though that settling time would be an issue...

If it were me, I would take multiple samples throughout the entire PWM cycle.. ie as many as I could muster.. Then workout how many to use afterwards. If it's calculable, try and sample in the middle of the PWM high.. After all you know in advance what the PWM duty cycle is...
 
If you have capacitive load, the max current will be immediately after you switch PWM from low to high. If you have inductive load, the max current will be immediately before you switch PWM from high to low. In case of resistive load, the current will be the same throughout the PWM high period.
 
Well the settling time is about 10uS from the start of the pulse based on the o'scope trace.
More importantly, am I correct in assessing a PWM low byte value of 192 is equivalent to the TMR2 value of 48?

The load is a nichrome wire across a battery.
 
Well the settling time is about 10uS from the start of the pulse based on the o'scope trace.
More importantly, am I correct in assessing a PWM low byte value of 192 is equivalent to the TMR2 value of 48?

The load is a nichrome wire across a battery.

You could say that. If you don't need 10-bit resolution, you simply ignore CCP1CON bits. CCPR1H (which is accessible only CCPR1L as I remember) then corresponds to TMR2.
 
CCPRxL value cannot exceed the value written to PR2. This means that 10-bit resolution is only available for PR2 values less than 128. Maximum 10-bit resolution is only available when PR2=255. The only way to increase the PWM period when PR2=255 would be to increase the oscillator frequency.

The lower duty cycle bits can be ignored if max resolution is not needed.
 
CCPRxL value cannot exceed the value written to PR2. This means that 10-bit resolution is only available for PR2 values less than 128. Maximum 10-bit resolution is only available when PR2=255. The only way to increase the PWM period when PR2=255 would be to increase the oscillator frequency.

The lower duty cycle bits can be ignored if max resolution is not needed.

That's a confusing statement. The bit about increasing period by increasing freq is inverted.
 
That's a confusing statement. The bit about increasing period by increasing freq is inverted.

Whoops...I'll correct that. Meant to say that for a greater PWM frequency (not period...but the period would in fact decrease...duh) when PR2=255 you would have to increase the oscillator frequency.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top