EM4095 Chip, get Clock and Data signals?


Closed Thread
Results 1 to 15 of 15
  1. #1
    Join Date
    Mar 2008
    Posts
    43

    Default EM4095 Chip, get Clock and Data signals?

    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

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    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...

  3. #3
    Join Date
    Mar 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    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!

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    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.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Mar 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    Yes, i want to get it translated to PBP, as mikroBasic's USB libary isn't very usefull and functional!

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    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 . . .
    Code:
    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
    Code:
    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
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7
    Join Date
    Mar 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    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?

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mindthomas View Post
    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.

  9. #9
    Join Date
    Mar 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    So you mean that i should make them Global too, as there aren't anything UnGlobal in PBP?

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mindthomas View Post
    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.

  11. #11
    Join Date
    Mar 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    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)

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mindthomas View Post
    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...

  13. #13
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Quote Originally Posted by mindthomas View Post
    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>
    DT

  14. #14
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    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'

  15. #15
    Join Date
    Mar 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    "Write for me" - no' not at all.
    I have converted some off the code myself!

Similar Threads

  1. Data Out From External Clock
    By Quin in forum Serial
    Replies: 2
    Last Post: - 25th October 2008, 09:11
  2. Data logger clock and array
    By PicLearner in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 25th September 2008, 04:19
  3. Shiftout/in
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 23rd August 2007, 11:48
  4. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  5. MAX1247 4-Channel, 12-Bit ADC
    By Atom058 in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 15th December 2006, 23:38

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts