PDA

View Full Version : Pulse count matching



RodSTAR
- 21st April 2008, 07:49
Hi all;

-In a 16F628A, I receive a pulse into a timer, in counter mode, let's say timer1.
Question:
-Is there any kind of interrupt flag or trick that tells me when it matches a specified count? (example: when TMR1=231)


I know QEI does it great in 18F4431 family members, but I don't have them, and I have 12 units of 16F628A here in my desktop.

Thanks for any ideas or comments

RodSTAR
- 21st April 2008, 08:06
Another detail is that at the same time I want to get pulse rate (to calc speed).
¿ Should I use:
-Timer0 (or timer1) as Timer and
-Timer1 (or timer0) as Counter...
... to feed my variables to calculate speed?

RodSTAR
- 21st April 2008, 08:39
I think in a possible solution:
Connect my pulse wire to RB6/T1CKI, that is Timer1 input pin, PORTB. Hope I can use RB Port Change Interrupt at the same time as Timer1 is ON. If it is possible, then:

To get pulse count:
-when INTCON.0=1 (alias RBIF) interrupt onchange in PORTB, increment MyCounter variable 'manually',
To get time interval:
-use Timer1 and calculate speed on each Timer overflow interrupt PIR1.0=1 (alias TMR1IF) or whenever i want

Is it possible that solution??



PD:
[It has come to my mind another question about Interrupts Identification in a new Thread...'Interrupts Identification']

HenrikOlsson
- 21st April 2008, 18:01
Hi,
Too many questions at the same time for me.... I'll start with the first one:

-In a 16F628A, I receive a pulse into a timer, in counter mode, let's say timer1.
Question:
-Is there any kind of interrupt flag or trick that tells me when it matches a specified count? (example: when TMR1=231)


There's at least two ways of doing this as I see it. Either you preset the TMR register with 65535-231 (for a 16bit timer) and when the timer/counter overflows you'll get your interrupt. OR you can use the CCP-module in compare mode, it's designed for doing exactly that. When TMR1 matches the CCPR1 register you'll get an interrupt.

/Henrik.

Acetronics2
- 21st April 2008, 19:46
Hi,

Just open the '628 datasheet ... CCP1 chapter



11.2 Compare Mode
In Compare mode, the 16-bit CCPR1 register value is
constantly compared against the TMR1 register pair
value. When a match occurs, the RB3/CCP1 pin is:
• Driven High
• Driven Low
• Remains Unchanged
The action on the pin is based on the value of control
bits CCP1M3:CCP1M0 (CCP1CON<3:0>). At the
same time, interrupt flag bit CCP1IF is set.
FIGURE 11-1: COMPARE MODE
OPERATION BLOCK
DIAGRAM
11.2.1 CCP PIN CONFIGURATION
The user must configure the RB3/CCP1 pin as

....



Isn't life superb ???

Alain

RodSTAR
- 22nd April 2008, 03:35
Hi Henrik & Alain;

I'm amazed with both excelent solutions you gave me :). I'll use them in other projects I have in mind.
Nevertheless, Alain's solution can't fit in this particular project, because it is a motor controller. (sorry, but I didn't tell it before to focus the thread on the specific part of the problem)

Why can't fit in my project?

Alain's CCP1 solution can't be possible, because as motor controller, I use the unique CCP module in PWM mode to drive motor's H-bridge. (remember it's a PIC16F68A)
Well, of course Alain (Acetronics) couldn't guess that CCP was unavailable: I had not told it.

To Henrik's solution, I'll add TMR0 in timer mode, as time reference, for speed calculation. A little bit uncomfortable (8-bit variable), but factible (I hope).

Thank you Alain and Henrick.

PD: I would be still more gratefull if any of you give me an opinion on my Post#3.

Regards!
Rodrigo