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.

How to count time between two interrupts? (USART)

Status
Not open for further replies.

kotsam

Member level 1
Joined
Nov 16, 2005
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,606
Hi all ,

i would some help please , how can i can i count time between two interrupts , what i mean for example i can have configured interrupt :

btfsc PIR1, RCIF ; Serial Port Reception interrupt

i need to set counter to be 0 when the first interrupt occurs , and when i send something new (second interrupt occurs to know when its occurs), cuz what i want to do ; is if the time differnce between both interrupts less than 4ms to do function and when its greater than 4ms to do something else , how can i do that btw i'm using ASM
 

Re: UART

Hi
you didn't mentioned the MCU you're using!

Could you give more explainations (serial data reception at which rate?, what do you mean by "functiion"?) on what you want to do?

The more you give infos the more we can help you !

Best regards
Kabanga
 

Re: UART

thanks very much for the replay ,
I'm using pic18fxx5x, baudrate 9600 , what i want to do exactly , is

to check the time differnce between first serial interrupt occur and second interrupt occur (for serail receive) ,

if the time deffrence between the first interrupt and the second one greater than 4ms , goto to do sort of operation in the program ,

if not goto to back until received two interrupts (serial interrupts) with deffernce of 4ms (simply , i want to receive RCREG with deffernce of 4ms , ) hope this is more clear . (what is required to configure counter which will be 0 at the first interrupt and check this counter at the second interrupt if it less that 4ms repeat and reset counter till counter value will be 4ms ) but i dont know how can i do that by ASM ???

Added after 5 minutes:

BTW ITS 20MHZ OSC
 

Re: UART

How are the data beeing sent to the PIC? I mean, is there any software that is sending automatically the data?
It's important to know how the data are sent!
 

Re: UART

yes , there is program sending data , through usart(rs232)
 

Re: UART

Have a look at this is piece of code (supposed you did all necessary initializations at a prior level): we are going to the Timer0 in 16-bit mode

movlw 0x0F ;initialize countH
movwf countH

movlw 0xA0 ;initialize countL
movwf countL

movlw 0x08 ;Timer0, 16-bit, int. clock, no prescaler
movwf T0CON ;load T0CON

movlw 0x0F ;initialize the timer0 registers TMR0H and TMR0L. The initialization
movwf TMR0H ;value is 0FA0. That correspond to 4mS delay
movlw 0xA0
movwf TMR0L

bcf INTCON,TMR0IF ;clear timer0 interrupt flag

Loop1:
btfss PIR1,RCIF ;serial data received?
bra Loop1 ;no, wait
bsf T0CON, TMR0ON ;yes, start Timer0
movff RCREG,TEMP1 ;read RCREG to make the way free for the next data
; and clear the RCIF flag

Loop2:
btfss PIR1,RCIF ;serial data received?
bra Loop2 ;no, wait
bcf T0CON,TMR0ON ; yes, stop the Timer0


At that point the Timer0 contain a value that you will compare with countH and countL. If countH=TMR0H AND countL=TMR0L, then the amount of time between
the reception of two serial bytes is equal to 4mS=> means you can implement one or more of your functions right here....

If they are not equal, then you implement another function....

It should be easier to implement.....

I didn't re-read my post. If you have any question, don't hesitate...
Hope it helps.

Best regards
Kabanga
 

Re: UART

Thanks all

I am also interested in pc interfacing with PIC.
Interruption process seems hard to me.
 

Re: UART

There are wonderful people on that forum who are really willing to help. But you don't specify your problem, how can somebody help you?

You said you are "interested in interfacing PIC and PC", well what is the point now? Did you try to interface PIC and PC and you couldn't succed? if yes, so you shoud tell people what you did and which problems you encountered. Then we can help you !!!

But if you are just interested in that item, it's very simple, you can just google !!!
Hope that helped!

Best regeards
Kabanga
 

UART

check the configuration bits..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top