PDA

View Full Version : EM4095 Chip, get Clock and Data signals?



mindthomas
- 16th August 2008, 17:49
Hi.
My problem is right now, that i have figured out that i can't do this without using interrupt, but first i will tell you why and how!

The EM4095 is a RFID chip which outputs a Clock signal and a Data signal.
Then you need to get EVERY Clock pulse (HIGH, LOW), but you can't do that with a normal WHILE Loop and then a "IF PORTB.1(Clock pin) = 1" as it would take to much time, and then have you maybe lost some clock pulses.

We need to get 128 bits of Data, and it's NOT equal 128 bits of Clock Pulses, look at this table to find out why:
1. Wait on the Falling Egde on the Data-Port
2. Wait 16 Clock Pulses (HIGH, LOW) from the Clock-Port
3. Collect first data on the Data-Port "PORTB.0 and 1"
4. Wait 32 Clock Pulses (HIGH, LOW) from the Clock-Port
5: Collect second data on the Data-Port "PORTB.0 and 1"
6: Point 4 and 5 is repeated 255 times

Every Clock pulses is counted with the interrupt on PORTB.1 (the Clock-Port)!
But my problem is, that i would like to do all this without using the Interrupt method, as if i'm in a While Loop and the interrupt then see a falling edge on the Clock-Port, then it interrupt's the While Loop, and my whole code is starting from the beginning again.
Therefor i can't do anything with my code, as it would interrupt!!! Damn thing...

I'm using a PIC18F4550 to you information.

Best Regards
Thomas Jespersen

skimask
- 17th August 2008, 06:43
Actually, I don't see why you couldn't do that with interrupts...
But, at any rate...
If you're that worried about missing a clock/data pulse, maybe put EVERY bit into a bit array while you are receiving it, including the initial 16 clock pulses, and every one of those 32 clock pulses and/or data bits into a big ol' bit array. Then after you've got all those clock/data pulses, run them thru the laundry after you get done receiving.

How fast are these clock pulses anyways? A nice, tight If/Then or While/Wend or Repeat/Until loop storing bits would be pretty dang fast... Unless you're trying to pull in something in the Mhz range... Ya, then you're probably looking at going into something a bit more specialized.

Are you afraid of using the interrupt method of doing things?
Once you try DT's Instant Interrupts and get used to them, you'll find that they are inherently fast, little (if any) wasted time, and might just be the ticket you want...

mindthomas
- 17th August 2008, 15:36
Originally the code that i was talking about, was written in mikroBasic, and not by me, but be the mikroElektronika team, and it's also them who had developed the RFID board..

This is the originally code from the mikroElektronika team (OBS. It's in mikroBasic, but it should be similar to PBP): www.tkjweb.dk/Orig_RFID.txt
And this is my code, just so you can see what i want to do: www.tkjweb.dk/My_RFID.txt

And i'm not sure why, but also i can't turn every PORTC or PORTD LED's on, also the PORTC.6 LED is flashing when i click on the button (PORTA.0) and it isn't going correctly into the While loop, or maybe it just skip everything, because when i release the button again, the does the LED turn off!

Archangel
- 17th August 2008, 20:50
Meaning no disrespect, Are you attempting to convert this to PBP, as I see no evidence of that. This forum is not for mikroBasic and their code will not compile on PBP, and PBP code likely will not compile on mikroBasic, like trying to breed an elephant to a rhino, you get ? elephanino. :) Anyway it does not work.

mindthomas
- 18th August 2008, 06:07
Yes, i want to get it translated to PBP, as mikroBasic's USB libary isn't very usefull and functional!

Archangel
- 18th August 2008, 06:37
OK I do not know anything about MikroBasic, I know a little "C" and it looks similar, Know this,
PBP variables are global, whereas C and I think Microbasic are not all global, in c you can make temporary variables that release the registers when not called, all this means is you will encounter variables in mikro and C that are not declared up front, and in converting you will have to, also PBP does not do FP math and uses unsigned integers unless you compile with PBL in which case you will have to use 18Fseries chips.
here is a few lines to get you started . . .


dim sync_flag, ' in the sync routine if this flag is set
one_seq, ' counts the number of "logic one" in series
data_in, ' gets data bit depending on data_in_1st and data_in_2nd
data_index, ' marks position in data arrey
cnt, ' interrupt counter
cnt1, cnt2 as byte ' auxiliary counters

data as byte[256]
data_valid as byte[64]

bad_synch as byte ' variable for detecting bad synchronisation

becomes

sync_flag VAR BIT ' in the sync routine if this flag is set
one_seq VAR BYTE ' counts the number of "logic one" in series
data_in VAR WORD ' gets data bit depending on data_in_1st and data_in_2nd
data_index VAR BYTE ' marks position in data arrey
cnt VAR BYTE ' interrupt counter
cnt1 VAR BYTE
cnt2 VAR BYTE ' auxiliary counters


data VAR BYTE[256] ' huge 256 byte array
data_valid VAR BYTE[64] ' 64 byte array

bad_synch VAR BYTE ' variable for detecting bad synchronisation

mindthomas
- 18th August 2008, 12:09
Thanks.
Also, when you say that Variable are global, then if you look at the mikroBasic code, then you would see that there are some variables made in the main section and also in a Procedure some variables are made, which can only be used in that Procedure!
So what about them?

skimask
- 18th August 2008, 14:02
Thanks.
Also, when you say that Variable are global, then if you look at the mikroBasic code, then you would see that there are some variables made in the main section and also in a Procedure some variables are made, which can only be used in that Procedure!
So what about them?

Use different variables.

mindthomas
- 18th August 2008, 15:28
So you mean that i should make them Global too, as there aren't anything UnGlobal in PBP?

skimask
- 18th August 2008, 15:32
So you mean that i should make them Global too, as there aren't anything UnGlobal in PBP?

I mean if they are truly global, then they are the same variable thru the program.
If they aren't, then the variable most likely has two different meanings in different, distinct functions/modules/subroutines.

In PBP, all variables are global, meaning that if temp holds a value here, it holds that same value over there, and over there, and over here.

mindthomas
- 18th August 2008, 16:48
Okey, thanks.
Could you help me with some more, especially the Interrupt, or if it could be done without using Interrupt!! (it could be great if it could be done without)

skimask
- 18th August 2008, 16:57
Okey, thanks.
Could you help me with some more, especially the Interrupt, or if it could be done without using Interrupt!! (it could be great if it could be done without)

Doubt it...

Darrel Taylor
- 18th August 2008, 20:46
Okey, thanks.
Could you help me with some more, especially the Interrupt, or if it could be done without using Interrupt!! (it could be great if it could be done without)

Doubt it...

Doubt what?

That it can be done without interrupts?

Or that you could help him?
<br>

skimask
- 18th August 2008, 21:07
Doubt what?
That it can be done without interrupts?
Or that you could help him?
<br>

I assume it can be done both ways...don't know, don't have the chip, haven't tried, looks like it's entirely possible either way.

The phrase 'help me' is a bit dubious...looks a lot like 'write for me'

mindthomas
- 19th August 2008, 06:27
"Write for me" - no' not at all.
I have converted some off the code myself!