PDA

View Full Version : Help with Count PORTB.0



jetpr
- 26th September 2008, 01:24
I need to find a circuit to made pulse to test the Count PORTB.0 to see if is reading correct ..

thanks for any help.

mackrackit
- 26th September 2008, 01:57
Use another PIC and FREQOUT.

jetpr
- 26th September 2008, 04:32
thanks for help

Bruce
- 26th September 2008, 06:43
Or use the same PIC with hardware PWM. This can output the pulse in the background
while COUNT works in the foreground.

Or use Timer1 in counter mode, and just loop through setting/clearing a pin connected to
the counter input.


DEFINE OSC 20 ' tested using a 16F877A on LAB-X1

DEFINE HSER_CLROERR 1 'Automatically clear any USART overflows.
DEFINE HSER_RCSTA 90h 'Set receive register to receiver enabled
DEFINE HSER_TXSTA 24h 'Set transmit register to transmitter enabled
DEFINE HSER_BAUD 9600 'Set baud rate
Tmr1Val VAR WORD
Loops VAR WORD
NumLoops VAR WORD
INTCON = 0 'Global interrupts disabled (peripheral interrupts disabled)
ADCON1 = 7 'All digital
TRISA = %00010000
TRISB = %01010001
TRISC.0=1 'Timer1 clock input connected to RA0

' Default idle logic on Timer1 counter input is logic 1
HIGH PORTA.0
TMR1L=0 : TMR1H=0
T1CON = %00000011
PAUSE 50
HSEROUT ["Begin",13,10]

Start:
' Generate a random number
RANDOM NumLoops

' Output random number of low-to-high pulses for
' Timer1 counter input
FOR Loops = 1 TO NumLoops
LOW PORTA.0
HIGH PORTA.0
NEXT Loops

' Read Timer1 count into word variable Tmr1Val
Tmr1Val.LowByte = TMR1L
Tmr1Val.HighByte = TMR1H

' Display count
HSEROut [" Random # = ",DEC NumLoops," Count = ",DEC Tmr1Val,13,10]

' Clear Timer1 count before starting over
TMR1L=0
TMR1H=0
goto start

END