Searching \ for '[pic]: timing calculation error' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'timing calculation error'.

Exact match. Not showing close matches.
PICList Thread
'[pic]: timing calculation error'
2003\08\04@194311 by andre abelian

picon face
Hi to all engineers,

I have 2 questions.

I need to generate 46.25 us interrupt this is how I calculated
     Using 16 mhz crystal  256-185=71 if I put 71 in timer0
    I should get  185/4=46.25 us interrupt. 2 cycle latency for
     Timer0 and 5 cycle latency for interrupt service routine I get
      71-2-5 should be 64 so if I put 64 in timer0 I should get close
     to 46us but it is not. By changing the number I got TMR0L=119
decimal
     now I am getting 46us interrupt. My test code is doing timer1 and
adc
     interrupt services too. Does any one know what I am doing wrong?
     Any help will appreciate.


2.      on pulse generation I am not using WDT at all it is disabled in
MPLAB ICE
but when I clear WDT on timer0 ISR I get better quality pulse (stable)
when I remove clear WDT the pulse starts shaky my question is
if WDT is disabled then why clearing WDT helps to stabilize the pulse
which is  BTG    portb,0  that is it
any idea or help will appreciate.


Andre

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu

2003\08\04@221612 by Olin Lathrop

face picon face
{Quote hidden}

I suggest you re-code your query in english.  This means sentences that have
a subject, predicate, start with an upper case letter, and end with a period
(those handy things that let your readers catch their breath).  While you're
at it, try formatting that looks like you actually respect the reader's
time.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu

2003\08\04@225435 by Andre Abelian

picon face
Olin,

Try again.

I am generating 46.25 us interrupt and this is how I calculated.
Using 16 mhz crystal with 8 bit timer 256(8 bit timer)-185(the value I
use)=71 so if I put 71 in timer0 I should get 185/4=46.25 us interrupt.
Now since there are timer0  (2 cycle) latency + interrupt (5 cycle)
latency now real number should be 71-2-5=64 so if I put 64 in timer0 I
should be able to get 46us but I am not getting 46us. By adjusting the
number to 119

TMR0L=119;  // decimal

Now I get every 46us interrupt
My test code also does timer1 and  adc  interrupt service routines like
Turning led on and off. Now my question is Does any one know why my
Calculation didn't work?
Any help will appreciate.

Andre

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu

2003\08\04@230058 by Jinx

face picon face
> I need to generate 46.25 us interrupt this is how I calculated
> Using 16 mhz crystal  256-185=71 if I put 71 in timer0
> I should get  185/4=46.25 us interrupt. 2 cycle latency for
> Timer0 and 5 cycle latency for interrupt service routine I get
> 71-2-5 should be 64 so if I put 64 in timer0 I should get close
> to 46us but it is not. By changing the number I got TMR0L=119

If I understand you correctly, you're using 2 + 7 extra cycles
outside of TMR0 so you'd add that to the 71 to make TMR0
run for a shorter time before it rolls over, ie TMR0 counts
(256 - (71+2+7)) * 0.25us = 44us.

Putting 64 in TMR0 would get you 192 * 0.25us = 48us. I can't
explain the 119. You aren't confusing it with 77h are you ?

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu

2003\08\05@075528 by Olin Lathrop

face picon face
> Try again.

Definitely better.

> I am generating 46.25 us interrupt and this is how I calculated.
> Using 16 mhz crystal with 8 bit timer 256(8 bit timer)-185(the value I
> use)=71 so if I put 71 in timer0 I should get 185/4=46.25 us interrupt.
> Now since there are timer0  (2 cycle) latency + interrupt (5 cycle)
> latency now real number should be 71-2-5=64 so if I put 64 in timer0 I
> should be able to get 46us but I am not getting 46us. By adjusting the
> number to 119

Don't try to account for the interrupt latency.  It is much better to add
a fixed value into timer 0 each interrupt.  16MHz clock means 4MHz timer 0
increment rate (assuming prescaler of 1).  1 / 4MHz = 250nS, which is the
timer 0 tick period.  46.25uS / 250nS = 185 timer 0 increments in your
desired interrupt period.

Left alone, timer 0 will cause an interrupt ever 256 ticks.  If you add
into TMR0, it misses 2 ticks, effectively making it 256 + 2 = 258 ticks
per interrupt.  258 - 185 = 73 too many ticks per interrupt period.
Therefore, you will achieve a 46.25uS interrupt period by adding 73 into
TMR0 each interrupt.

This assumes the prescaler is set to 1:1, meaning it must be assigned to
the watchdog timer instead of timer 0.  Of course the accuracy is
proportional to the accuracy of the CPU oscillator.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\08\05@154819 by andre abelian

picon face
Olin,

Thanks for your replay.
I guess mastering (interrupt service routine) is not easy
Even I get precise timing after adding more codes
Timing gets changed more adjustments needed more changes needed
I also found one more problem with mplab 6.22.
Using same code with mplab 6.22 will generate different timing on timer0
then mplab 6.30 does.

Andre




{Original Message removed}

2003\08\05@161753 by Denny Esterline

picon face
Andre,
This may have already been discussed, but I was curious as to what you need
such a precise (and seemingly arbitrary) time value for?
Denny


----- Original Message -----
From: andre abelian <EraseMEengelecspam_OUTspamTakeThisOuTEARTHLINK.NET>
To: <PICLISTspamspam_OUTMITVMA.MIT.EDU>
Sent: Tuesday, August 05, 2003 3:50 PM
Subject: Re: [pic]: timing calculation error


{Quote hidden}

> {Original Message removed}

2003\08\05@180544 by Jinx

face picon face
> I also found one more problem with mplab 6.22.
> Using same code with mplab 6.22 will generate different
> timing on timer0 then mplab 6.30 does.

We've probably all had our moments with MPLAB, but that's
an interesting one. Are you talking about Stopwatch ?

BTW, I found my own little gotcha with 6.0.20 the other day.
"skpnz" macro had been mis-typed as "sknz" but there was
no compilation (ie red fail) MPASM error.  "Found label after
column 1. (SKNZ)" is in the .err file though. As this is code
being moved from the F628 to F452 I'm on the lookout for
errors, and will now pay more attention to MPASM's assembly
report, even if the assembly appears to have been successful

andlw   0x01     ->     andlw 0x1
skpnz                 ->     btfsc 0xfd8, 0x2, 0
bra     sxno        ->     bra  0x79e

andlw  0x01      ->      andlw 0x1
sknz                   ->      not compiled
bra  sxno           ->      bra 0x79c

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\08\05@195643 by andre abelian

picon face
Denny,

This is for power inverter that from 0-360 must be 16.66 ms
16,66/360=46.27us  but we are getting 46.25us

Andre


{Original Message removed}

2003\08\05@200055 by andre abelian

picon face
Jinx,

I always use emulator with digital scope.
That is why this calculation made me crazy
Just because of mplab compatibility.

Andre


{Original Message removed}

2003\08\05@203252 by Tom

flavicon
face
At 04:59 PM 8/5/03 -0700, you wrote:
>Denny,
>
>This is for power inverter that from 0-360 must be 16.66 ms
>16,66/360=46.27us  but we are getting 46.25us
>
>Andre

Andre, you have some interesting numbers here.

You don't like the error from this:
46.25us * 360 = 0.016650000 ; reciprocal = 60.060060060

when you say you want this:
46.27us * 360 = 0.016657200 ; reciprocal = 60.034099368

but this seems like this might be closer:
46.296296us * 360 = 0.016666666667 ; reciprocal = 60.00000000

*If* you are trying to produce 60.00000 Hz, it *looks* like 46.27us is not
the correct value either.  Of course, there is probably plenty we don't
know about what you are trying to do.  I was suspicious of round off error
when you called out 16.66 ms in your last email.

Just curious.
Tom

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\08\06@002921 by Mike Singer

picon face
andre abelian wrote:
> I guess mastering (interrupt service routine) is not easy.
> Even I get precise timing after adding more codes timing
> gets changed; more adjustments needed more changes needed.
>
> I also found one more problem with mplab 6.22. Using same
> code with mplab 6.22 will generate different timing on
> timer0 then mplab 6.30 does.

Is this interrupt's hassle really needed?

Google with:
"Timer polling Scott Dattalo"
or "isochronous code Scott Dattalo"

Mike.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\08\06@005325 by Scott Dattalo

face
flavicon
face
On Wed, 6 Aug 2003, Mike Singer wrote:

> andre abelian wrote:
> > I guess mastering (interrupt service routine) is not easy.
> > Even I get precise timing after adding more codes timing
> > gets changed; more adjustments needed more changes needed.
> >
> > I also found one more problem with mplab 6.22. Using same
> > code with mplab 6.22 will generate different timing on
> > timer0 then mplab 6.30 does.
>
> Is this interrupt's hassle really needed?
>
> Google with:
> "Timer polling Scott Dattalo"
> or "isochronous code Scott Dattalo"

Interesting, the first link has code attributed to me that I know I didn't
write (I never have written anything for an SX)

I wanted to suggest the isochronous approach earlier, but I'm not sure I
understand what Andre really wants. If he's beating his head against a
simple interrupt issue, then I'm not sure how or if isochronous coding
will make his life easier. BTW, if this is for a midrange part, isn't true
that most of the time the interrupt latency is 1 instruction cycle, but
sometimes it's 2? In which case, any software based delay based on
interrupts will have 1 cycle of jitter.

Scott

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\08\06@005327 by Andre Abelian

picon face
Tom,

You are right but how to get it closer?

Andre

-----Original Message-----

At 04:59 PM 8/5/03 -0700, you wrote:
>Denny,
>
>This is for power inverter that from 0-360 must be 16.66 ms
>16,66/360=46.27us  but we are getting 46.25us
>
>Andre

Andre, you have some interesting numbers here.

You don't like the error from this:
46.25us * 360 = 0.016650000 ; reciprocal = 60.060060060

when you say you want this:
46.27us * 360 = 0.016657200 ; reciprocal = 60.034099368

but this seems like this might be closer:
46.296296us * 360 = 0.016666666667 ; reciprocal = 60.00000000

*If* you are trying to produce 60.00000 Hz, it *looks* like 46.27us is
not
the correct value either.  Of course, there is probably plenty we don't
know about what you are trying to do.  I was suspicious of round off
error
when you called out 16.66 ms in your last email.

Just curious.
Tom

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\08\06@013534 by Mike Singer

picon face
Scott Dattalo wrote:
> I wanted to suggest the isochronous approach earlier, but
> I'm not sure I understand what Andre really wants. If he's
> beating his head against a simple interrupt issue, then I'm
> not sure how or if isochronous coding will make his life
> easier...

It could, perhaps. It seems, that at current level of his app
development he might want to try just a simplest loop.

Mike.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\08\06@013538 by Mike Singer

picon face
Get varicaps (thing that vary their capacitance under varying
voltage) in place of the XTAL capacitors. Control them by PIC.

Reference the resulted frequency to some standard frequency
source (mains for example, but I don't know if you mains
frequency is stable enough).

Mike.



Andre Abelian wrote:
{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\08\06@041953 by Alan B. Pearce

face picon face
>You are right but how to get it closer?

Why do you need it closer ????

with 60.06Hz you are less than 1/10th of 1% off your design frequency, which
looks like you are attempting a UPS as a project.

Again why do you need the 60hz so accurate.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\08\06@063951 by Samo Benedicic

picon face
I think ten or so days ago someone posted code
fragment that deals with this 1 cycle jitter issue.

Samo

{Quote hidden}

http://www.piclist.com/#topics


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\08\06@075405 by Olin Lathrop

face picon face
andre abelian wrote:
> This is for power inverter that from 0-360 must be 16.66 ms
> 16,66/360=46.27us  but we are getting 46.25us.

Duh!  This is wrong, and sounds silly anyway.

The period of a 1 degree phase change of a 60Hz sine wave is 1 / (60Hz *
360deg/Hz) = 46.30uS/deg.  Therefore 46.27uS is actually closer than
46.25uS, but neither is accurate to within the 4 implied digits.

Furthermore, why does this inverter need to do whatever it does exactly
every 1 degree?  Degrees are a human convention, but there is otherwise
nothing magic about 1/360 of cycle.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\08\06@114531 by Scott Dattalo

face
flavicon
face
On Wed, 6 Aug 2003, Samo Benedicic wrote:

> I think ten or so days ago someone posted code
> fragment that deals with this 1 cycle jitter issue.

I must've missed it among the flurry of rediculously off topic posts we've
had lately. (What's the deal with asking questions about Excel on a
microcontroller mailing list? My question is rhetorical *please* don't
waste time answering it!)

But back on topic....

Was it something like this:

  ; interrupt code .....

  ; If TMRO is not the value we expect it to be then (presumably)
  ; we were delayed one extra cycle when the interrupt occurred

      MOVLW   TMR0_KNOWN_VALUE_RIGHT_NOW
      SUBWF   TMR0,W
      SKPZ                           ;If TMR0 is not what we expect
       GOTO   $+1                    ;then delay one cycle.

Changing the subject slightly...

I very often have to deal with timing; e.g. converting instruction cycles
into milliseconds or whatever. It's always easy to make a mistake doing
these tedious conversions. So as general advice, I suggest carrying units
along with the numbers during your conversions. It's a trick you're taught
(or should've been taught) in Freshman Physics.

So for example, let's suppose you want to know how many instructions
execute in 1/60'th of a second on a midrange PIC clocked at 10MHz.

fosc = 10Mhz = 10million cycles/second
Tosc = 1/fosc = 100 nSecond/ cycle
Tinst = 4 cycles/instruction *Tosc
     = 4 cycles/instruction * 100nSeconds/cycle
     = 400 nSeconds/Instruction
Tinterval = 1/60 seconds/Interval

Now, to find the number of instructions per the 1/60'th of a second
interval we need an answer that has the units of Instruction/Interval:

                  1    seconds      400  nSeconds
Tinterval/Tinst = --- * --------  / --------------
                  60   Interval      Instruction

                  1    seconds       Instruction
               = --- * --------  *  -------------
                  60   Interval      400 nSeconds

                       1        Instruction
               = ------------ * -----------
                  60 * 400e-9    Interval

               = 41666.666...  Instructions/Interval

In summary, identify the units of all your variables and carry them along
in your analysis. This approach works well with timer prescales and
rollovers too.

Scott

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\08\06@134131 by andre abelian

picon face
Olin,

Main idea for counting from 0-360 is that there are 4
Pulses top 2 and bottom 2 they run at 60hz no matter what
And they move right and left.
Their normal startup looks like this:
Top2 starts at 180degree and bottom 2 starts at 28degree now
That's when x register=28 default. When x register changes becomes
29 top 2 pulses moves 1 degree left which is 179 degree and
bottom 2 moves 1 degree right becomes 29 degree. 60 hz never gets
changed. Top2 and bottom2 they are inverted from each other this
is how inverters generate sinusoid. It looks like 47,25 us
is ok to use but your calculation is better. I didn't want to talk about

it in detail because people do not want to read long e-mail.
After all final output looks like this.

           <== moves left
    B1     T1
    |------|                  |------|
    |      |                  |      |
------      |-----|      |-----|      |-----
                 |      |
                 |------|
                 B2     T2
               ==> moves right

B1 = rising edge of bottom pulse
B2 = falling edge of bottom pilse
Same thing for T1 and T2.
based on battery voltage and current load x register will
be updated in order to keep stable 110v 60 hz 40amp sinusoid.

Andre Abelian





{Original Message removed}

2003\08\06@144411 by andre abelian

picon face
Scott,

Sorry I do not know much about isochronous
I know that isochronous is used on transmit and receive
Application where each data contains speed information
Etc but I never used it before needs more studding.
Using loop is not going to work in my application
Because of background code shouldn't stop.

Andre


{Original Message removed}

2003\08\06@221902 by Mike Singer

picon face
Hey andre,

Why not just PWM at 60 Hz? (Did you hear of PWM?)
Invert every other pulse.

Mike.

andre abelian wrote:
{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\08\09@014338 by Mike Singer

picon face
Hi andre,

There were more than 20 posts on this thread.
Scott Dattalo, Olin Lathrop, Jinx and others were involved.
These gentlemen do deserve to be held in respect.

Could you post few words in conclusion, please.

Mike.


{Quote hidden}

all
{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
KILLspampiclist-unsubscribe-requestKILLspamspammitvma.mit.edu

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...