CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

delay between 2 events

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
shoyur



Joined: 18 Oct 2008
Posts: 6

View user's profile Send private message

delay between 2 events
PostPosted: Sat Dec 11, 2010 4:09 pm     Reply with quote

Maybe its a very simple question...

I need to know the time elapsed between 2 events,
3 inputs called : CK1, CK2, DATA

CK1-2 are for synchronizing (timing signals), DATA is a 16 bits serial data,
before I read data, there's a start signal, that is CK1+CK2 at high for 100uSec,
How to:
(pseudo)
Code:

if (ck1 & ck2 = 1) x = PresentTime
while (ck1 & ck2 != 0) do nothing
else delay = PresentTime minus x

if delay >= 100uSec then start checking for data

I hope I'm clear Smile

Thank you !

Oh and also, only if possible, is there a way to make an interruption with 2 different inputs at the same time, like checking for if ck1 and ck2 are high at same time without having to monitor it with an endless while.
Or maybe its not a bad thing to let the pic run a endless loop forever.

big thx !!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Dec 11, 2010 4:42 pm     Reply with quote

If you have some interface specification that you're trying to decode,
it's better if you tell us the name of the specification, and the manufacturer
and part number of the device. Code may already exist for it.
If there is a data sheet for the device, post a link to it.

Also post your PIC and CCS compiler version.
shoyur



Joined: 18 Oct 2008
Posts: 6

View user's profile Send private message

PostPosted: Sun Dec 12, 2010 12:45 pm     Reply with quote

version is PCWH 4.114
PIC16F877A

and its a digital radio tuner chip
Toshiba TC9147BP

http://www.datasheetcatalog.org/datasheets/2300/499314_DS.pdf

p.234-235 (not the pdf page but the printed page on image, its scanned pages pdf)

thank you
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 13, 2010 12:50 am     Reply with quote

You could read the data with an INT_EXT interrupt routine.
Let's say the PIC is running at 4 MHz. It takes about 30 instruction cycles
to get into the interrupt routine for a 16F-series PIC, if you only have one
interrupt routine. So at 4 MHz, this will take 30us.

On page 24 of the PDF link that you posted, it shows the detailed timing
of the incoming pulses. You could use the CK1 and DATA signals.
Connect CK1 to the External Interrupt pin. Set the interrupt to trigger on
the rising edge. The short CK1 pulses are only 20us long, and the Start
pulse is 100 us. It takes 30us just to get inside the int_ext isr, so you can
tell if you're in the Start pulse by just reading the CK1 line just after you
enter the isr. If you read a logic high level ('1'), then you've found the
Start pulse. You can set a static flag inside the isr to True, to indicate
to your isr code that you are "in progress" of clocking in a data word.
Or you could load a static byte variable with 17. Use this byte as a
"down counter" to indicate how many more interrupts must occur for
you to get all the data bits in the incoming word.

Then on the next interrupt, skip the next CK1 pulse. Then on the next 16
CK1 pulses (which means in the next 16 interrupts), read the DATA line
just after arriving in the isr, and left-shift the result into a global 'int16'
variable. Then set a global flag when it's finished, to tell the main code
that new data is available. Clear this flag when you start receiving a new
data word in the isr, so the main() routine won't try to read the global
'int16' value while it's being updated in the isr. Or, you could use a
circular buffer to store several sequential words, as you receive them
in the isr.

When you read the 16-bit global data word in main(), you will need to
disable interrupts temporarily. That's because you don't want to read the
data word and have the 2nd byte be changed by an interrupt while you
are reading the 1st byte in main().

I don't know the interval at which the Toshiba chip sends out a block of
data. Maybe the data sheet gives this information somewhere.

I don't want to do this project for you. I have given you an outline of
one possible way to do it. I don't want to do it for you.
shoyur



Joined: 18 Oct 2008
Posts: 6

View user's profile Send private message

PostPosted: Mon Dec 13, 2010 11:09 am     Reply with quote

It sends data each time the user press a new command (+, -, fm, am, seek, etc.) so its not too fast.

Only using CK1 as reference for data is good idea.
The fact that 30uS is shorter than the start signal and longer than CK1 signals is excellent idea.
and removing interrupt while the 17+ bits enters is good too.

Thank you a lot. It answers well my problem.

Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 13, 2010 2:08 pm     Reply with quote

Quote:
and removing interrupt while the 17+ bits enters is good too.

Actually, I didn't say to do that. I said the exact opposite. In fact, I
put in a line in parenthesis to make clear that I didn't want you to turn
off interrupts after the 2nd interrupt:
Quote:

Then on the next 16 CK1 pulses (which means in the next 16 interrupts),
read the DATA line just after arriving in the isr, and left-shift the result
into a global 'int16' variable.


The reason for keeping interrupts enabled is because I assume you have
some other process going on in main(), which you don't want to be
stopped for a long period of time. According to the Toshiba data sheet,
the whole cycle is 1.8ms. If you stay in the interrupt routine after the
2nd interrupt, then main() will be stopped for 1.7ms.
shoyur



Joined: 18 Oct 2008
Posts: 6

View user's profile Send private message

PostPosted: Mon Dec 13, 2010 6:02 pm     Reply with quote

Yes I didn't answer the right thing but understood what you meant (not removing interrupt but be sure it doesn't restart at beginning, considering its not a new start signal but just the continuous data per interrupt), yes I will come back in main and continue none stop.

thx again
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group