Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Question about timing in PIC16F84A

Status
Not open for further replies.

seadolphine2000

Advanced Member level 3
Joined
Apr 12, 2005
Messages
880
Helped
122
Reputation
244
Reaction score
87
Trophy points
1,308
Activity points
7,372
Hi,..

I have a PIC16F84A and I made a lot of projects and they work fine except one thing which is the timming. I made a timer with 7-seg. that count till 99, I wrote the software with delay 1000msec between one count and another, but when I use a stopwatch to check the time I found that 10 counts with PIC make 21 seconds on my watch.

Any ideas why this happends.????

P.S.: I use 4MHz crystal and two 22pF capacitors.

Thanks for help. :)
 

Re: PIC16F84A Timming

Without knowing your code on counting time it is impossible to advice you what could be the possible problem.
If you were some µs out off the counter then this would be pretty normal deviation, but 210% fault is rather suspicous..
Regards,
IanP
 

Re: PIC16F84A Timming

Maybe you increase counter twice before time out. So your pic watch goes quickly.

regrads,
 

Re: PIC16F84A Timming

Here you are the code:
program xdisplay2a

dim i as byte
dim j as byte
dim v as byte
dim por1 as byte
dim por2 as byte


sub function mask(dim num as byte) as byte ' this function returns masks

select case num ' for common cathode 7-seg. display
case 0 result = $3F
case 1 result = $06
case 2 result = $5B
case 3 result = $4F
case 4 result = $66
case 5 result = $6D
case 6 result = $7D
case 7 result = $07
case 8 result = $7F
case 9 result = $6F
end select'case end
end sub

sub procedure interrupt

if v=0 then
portb=por2 ' prepare mask for digit
porta=1 ' turn on 1st, turn off 2nd 7seg.
v=1
else
portb=por1 ' prepare mask for digit
porta=2 ' turn on 2nd, turn off 1st 7seg.
v=0
end if
TMR0=0
INTCON=$20
end sub

main:
OPTION_REG = $80
por2 = $3F
j = 0
TMR0 = 0
INTCON = $A0 ' Disable PEIE,INTE,RBIE,T0IE
trisa = 0
trisb = 0
portb = 0
porta = 0
do
for i = 0 to 99 ' count from 0 to 99
j = i mod 10
POR1 = mask(j) ' prepare appropriate digit
j = (i div 10) mod 10
POR2 = mask(j) ' prepare appropriate digit
Delay_ms(1000)
Next i
loop until false
end.
 

Re: PIC16F84A Timming

hi , sorry by my poor english

The instruction timing (for any instruction) are not equals, verify whit the datasheet, therefore and you can increase with "nop" this time. Its a common problen for me, "test and error" metod implemented for solucion.

regards
 

Re: PIC16F84A Timming

hai

for almost nearly i second delay you can use timer0 in timer mode
to generate 10.00001ms delay
you should load the value 0xd9 in TMR0
and the OPTION = 0x07
that means you are using the timer0 in timer mode with 1:256 ratio
this will work very well you will get more accurate value

best of luck
 

Re: PIC16F84A Timming

To be honest, this is not my software. I found it in a tutorial that comes with the mikrobasic program(tutorial attached). Check chapter 7

I'm trying to understand the code now, but this problem in time made me confused, I tested it again 3 times and the result was the same: 10 seconds on stopwatch = 21 seconds with PIC.

If you have some ideas about my problem, please tell me in a simple way.

Thanks to all of you. :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top