Searching \ for '[PIC]: Timer1 as a software counter 16f628' 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/time.htm?key=time
Search entire site for: 'Timer1 as a software counter 16f628'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Timer1 as a software counter 16f628'
2002\10\18@234131 by ards, Justin P

flavicon
face
Hello,

Can the Timer1 Module a 16F628 (@4Mhz) be used as a software 16bit counter.

I have scanned the last 30000 emails and looked at PICLIST.com  but all the
discussion seems to be using it driven via hardware.

I was experimenting with MPLAB and I got TMR1L to rollover to FF when I
decremented TMR1H from FF to 00 but cant repeat the results. I tried all
other combinations but they both appear to behave has 2 separate 8 bit files
when using decf or incf

I thought perhaps MPLAB does not simulate the TMR1 faithfully.

What I am trying to do is see how many 26uS units there are in a ext pulse.
Using 8 bits for counter the max pulse width is 6.6mS. 16bit gives 1690mS.

I got TMR0 to generate 26uS periods but the overheads involved in context
saving and bank switching did leave much time for anything else.  It did
work but not enough time to see if an 8bit counter rolled over and then inc
another counter.

If Timer1 behaved as a 16bit software counter it would save much in
overheads and be a great solution.  Anyone used it this way.

It appears I may need to increase the PIC speed if not.

Regards

Justin Richards (T388)
IS&W Meekatharra (Northern Remote)

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


2002\10\19@005350 by Mike Singer

picon face
Richards, Justin P wrote:

> What I am trying to do is see how many 26uS units
> there are in a ext pulse.

This should be the first sentence of your posting, I think.
One of the numerous solutions might be:
1. Use any timer to count number of your XTAL 4Mhz
pulses within your pulse, as described in 00592d.pdf
(AN592 Frequency Counter, Using PIC16C5X)
2. Recalculate this number to the number of 26uS units in
your pulse, using Olin's floating point code for example,
if needed.

  Good luck.

  Mike.

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


2002\10\19@184827 by Olin Lathrop

face picon face
> Can the Timer1 Module a 16F628 (@4Mhz) be used as a software 16bit
counter.

Depends what you mean.  The clock source is either derived from the
instruction clock or an external pin.

> I have scanned the last 30000 emails and looked at PICLIST.com  but all
the
> discussion seems to be using it driven via hardware.

That was 30,001 emails ago.

> I was experimenting with MPLAB and I got TMR1L to rollover to FF when I
> decremented TMR1H from FF to 00 but cant repeat the results. I tried all
> other combinations but they both appear to behave has 2 separate 8 bit
files
> when using decf or incf

Right.  They only act as one 16 bit register when incremented by the
hardware, and sometimes in conjunction with the CCP module.  I think you can
set the timer 1 source to RB6, set up RB6 as an output, then toggle RB6 from
software, although I haven't tried this.

> I thought perhaps MPLAB does not simulate the TMR1 faithfully.

It usually does a pretty good job of these things.

> What I am trying to do is see how many 26uS units there are in a ext
pulse.
> Using 8 bits for counter the max pulse width is 6.6mS. 16bit gives 1690mS.
>
> I got TMR0 to generate 26uS periods but the overheads involved in context
> saving and bank switching did leave much time for anything else.  It did
> work but not enough time to see if an 8bit counter rolled over and then
inc
> another counter.
>
> If Timer1 behaved as a 16bit software counter it would save much in
> overheads and be a great solution.  Anyone used it this way.

It sounds like you are trying to use timer 1 backwards.  Let the hardware
increment it at a steady rate, and take a snapshot of it at the begginning
and end of the period you want to measure.  The CCP module in capture mode
can help do this very accurately.  This is the basis for many frequency
measurement type applications.


*****************************************************************
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


2002\10\19@185239 by Olin Lathrop

face picon face
> 2. Recalculate this number to the number of 26uS units in
> your pulse, using Olin's floating point code for example,
> if needed.

Since timer 1 is guaranteed to be only 16 bits, I would use fixed point
multiply with 32 bit result.  Sorry but I don't give away the good stuff,
which includes the fixed point and floating point math routines.


*****************************************************************
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


2002\10\19@215117 by Bob Ammerman

picon face
Let TIMER1 free run.

Read it at the beginning and end of the pulse you are trying to measure.

Compute the difference and you are done.

Note that you'll get the right answer even if the timer has rolled over
during the pulse, as long as it hasn't rolled over more than once.

Bob Ammerman
RAm Systems



{Original Message removed}

2002\10\20@014951 by ards, Justin P

flavicon
face
Thanks for the replies gentlemen.

The problem I have is that various width pulses up to 90 keep rolling in so
I don't have much time to do processing and store them before the next
pulse.  A 16bit software counter would work like a charm

One solution which worked well but only for pulses less than 6.6mS was for
TMR0 to interrupt every 26uS and increment INDF, and use interrupt on Portb
change to increment FSR.  Elegant I thought although interrupt overheads
still created slight precision problems (but they are there anyway.)

Compare capture is the solution I will try to implement.  I need to encode
quickly a 16bit number into a 8 bit number for pulses greater than 6.6uS as
I have limited RAM (96 bytes) and need to store about 90 'times'.  If I cant
cram all I need into 26 instructions I will try toggling Rb6 as suggested, I
like the sound of this. If both these fail i will increase processor speed.

Thanks Again
Justin

{Original Message removed}

2002\10\20@040500 by Mike Singer

picon face
Richards, Justin P wrote:
.
> I need to encode quickly a 16bit number into a 8 bit
> number for pulses greater than 6.6uS as I have
> limited RAM (96 bytes) and need to store about 90
> 'times'.  If I cant cram all I need into 26 instructions
> I will try toggling Rb6 as suggested, I like the sound
> of this. If both these fail i will increase processor speed.

Add extra 2 bucks and start with PIC18F242.

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



'[PIC]: Timer1 as a software counter 16f628'
2002\11\07@061310 by Jinx
face picon face
> Richards, Justin P wrote:
> .
> > I need to encode quickly a 16bit number into a 8 bit
> > number for pulses greater than 6.6uS as I have
> >
> > If both these fail i will increase processor speed.
>
> Add extra 2 bucks and start with PIC18F242.
>
>  Mike.

I ran into a similar problem measuring events less than 6us
and doing calcs based on the period recorded so switched
to the 50MHz SX for that particular interface. With 20ns
instruction cycle times vs 200ns on the F628, problem gone

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


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