Show Posts
Pages: 1 [2] 3
16  Topics / Science and Measurement / Re: Reading data at 10 Khz rate on: November 13, 2012, 02:07:06 am
Hi guys I am back with another problem.
If i want to read the data exactly on each rising edge using interrupt how to approach that way???
All other things mentioned earlier still remains same ( reading "CAAC1F" and match found read the next remaining 32 bytes of data).
I have never written an ISR and pretty clueless how to set the proper register(currently i am going through the datasheet but without any background knowledge i am struggling a lot)
Any help???
Thanks in advance
Niladri 
17  Topics / Science and Measurement / Re: Reading data at 10 Khz rate on: October 05, 2012, 02:35:10 am
The code on post 32.
Some time that code also looses its Sync but once it looses it comes back after 2-3 wrong value
No in that code you have checked only 32 byte and after you skip a pules but data stream is continuous so pulse skip might not possible

Code:
const int CLOCK_PIN     =     2;
const int DATA_PIN      =     4;
const int PACKET_BITS   =     128;
const int PREAMBLE_LEN  =    6;
const int DATA_LEN      =    ((PACKET_BITS / 4) - PREAMBLE_LEN);

enum {
    PRE_0,    PRE_1,    PRE_2,    PRE_3,    PRE_4,    PRE_5,    DATA
} states;   

byte     preamble [] = {0x0C,0x0A,0x0A,0x0C,0x01,0x0F};
char     hexAsciiVals[] = "0123456789ABCDEF";
byte     state = PRE_0;
byte     nibble;
int        nibble_count = 0;

void setup() {
  pinMode(CLOCK_PIN, INPUT);
  pinMode(DATA_PIN, INPUT);
  Serial.begin(9600);
}

void loop() {

    nibble = getNibble();
    nibble_count++;
   
    switch (state) {   
        case PRE_0:
            if (nibble_count > 32) { // I made this change for my own understanding
                // we've read 32 bytes and still not found a match
                // for the preamble so skip a clock pulse
                while (digitalRead(CLOCK_PIN) == HIGH);
                while (digitalRead(CLOCK_PIN) == LOW);
                nibble_count = 0;
            } else {
                state = (nibble == preamble[0]) ? PRE_0 : PRE_1;
            }
            break;
       
        case PRE_1:
            state = (nibble == preamble[1]) ? PRE_0 : PRE_2;   
            break;
           
        case PRE_2:
            state = (nibble == preamble[2]) ? PRE_0 : PRE_3;
            break;

        case PRE_3:
            state = (nibble == preamble[3]) ? PRE_0 : PRE_4;
            break;

        case PRE_4:
            state = (nibble == preamble[4]) ? PRE_0 : PRE_5;
            break;
       
        case PRE_5:
            state = (nibble == preamble[5]) ? PRE_0 : DATA;
            break;
           
        case DATA:
            Serial.write (hexAsciiVals[nibble]);
            if (nibble_count == DATA_LEN) {
                // all done, start again
                state = PRE_0;
                nibble_count = 0;
            }
            break;
    }
}

byte getNibble() {

    byte val = 0;
   
    for (byte bit_count = 0; bit_count < 4; bit_count++) {
        while (digitalRead(CLOCK_PIN) == HIGH);
       
          while (digitalRead(CLOCK_PIN) == LOW);
       
          val <<= 1;
          val |= digitalRead(DATA_PIN);
       
         
    }
    return (val &= 0x0F);
}
 
18  Topics / Science and Measurement / Re: Reading data at 10 Khz rate on: October 05, 2012, 12:55:08 am
Ok this code is most efficient so far once it goes out of Sync in 2-3 iteration it comes back but they are saying make it like sliding window and you keep on sliding 1 bit at a time until you found the match("CAAC1F") and when found send it reaming bits(128-24=104) and again start the process. Can it be done?
Thanks and Regards
Niladri     
19  Topics / Science and Measurement / Re: Reading data at 10 Khz rate on: October 04, 2012, 01:01:45 am
Just for curiosity can ISR(edge triggered) be used at that frequency
20  Topics / Science and Measurement / Re: Reading data at 10 Khz rate on: October 03, 2012, 11:56:17 pm
Yes you are absolutely right though its reads corrects value some times but once its looses its sync it does take lot of value to again com its actual position. So what could i do to make to once it looses its sync on next or in 2-3 iteration its sync again.  smiley-sad   smiley-sad
Code:
const int pin2 = 2;
const int pin4 = 4;
int clock = 0;
int clock1 = 0;



void setup()
{
  pinMode(pin2, INPUT);
   
  pinMode(pin4, INPUT);
 
  Serial.begin(2400);
}
void loop()
{
     static byte num_bits  = 0;
     static byte value = 0;

     clock = digitalRead(pin2);
     if ((clock == HIGH) && (clock1 == LOW))
        {   

           
            value = (value << 1) | digitalRead (pin4);
            if (++num_bits >= 8)                          // have we done 8 iterations?  If so print it out
                {
                     Serial.print(value, HEX);
                     Serial.println();
                     num_bits = 0;
                    value = 0;
                }
        }

    clock1= clock;
}
21  Topics / Science and Measurement / Re: Reading data at 10 Khz rate on: October 03, 2012, 07:50:37 am
Thanks a lot sir it is working cann't express the joy of seeing it works in words
Thanks thanks thanks and also my respect and gratitude to all Rob, Geoff , Mike without your help and suggestion it would have not been possible

Thanks to everybody for response will come back to you when stuck with another problem(i have very little knowledge so it is highly unlikely that i can say something anybody problem)

Thanks a lot
Niladri
22  Topics / Science and Measurement / Re: Reading data at 10 Khz rate on: October 03, 2012, 06:41:44 am
Through another arduino i am feeding 0x0F but in other arduino(receiver) i am reading all kind of junk values but not 0x0F what could be the mistake on my part
Code:
const int pin2 = 2;
const int pin4 = 4;
int clock;
int clock1;



void setup()
{
  pinMode(pin2, INPUT);
   
  pinMode(pin4, INPUT);
 
  Serial.begin(2400);
}
void loop()
{
  static byte val  = 0b00000001;
  static byte value = 0b00000000;

    clock = digitalRead(pin2);
    if ((clock == HIGH) && (clock1 == LOW)) {   
       val <<= 1;

         value |= digitalRead(pin4);
         value <<= 1;
             if(val | 0x80) {   // flag bit has reached the top of the byte so we've done 8 iterations
           

           
                     
           Serial.print(value, HEX);
           Serial.println();
           val = 0b00000001;
          // value = 0b00000000;
         
         }
   
   
    }
    clock1= clock;
}
Thanks in advance
Niladri
23  Topics / Science and Measurement / Re: Reading data at 10 Khz rate on: October 03, 2012, 05:58:14 am
Sorry for that last code
Code:
const int pin2 = 2;
const int pin4 = 4;
int clock;
int clock1;

void setup()
{
  pinMode(pin2, INPUT);
   
  pinMode(pin4, INPUT);
 
  Serial.begin(2400);
}
void loop()
{
  static byte val  = 0b00000001;

    clock = digitalRead(pin2);
    if ((clock == HIGH) && (clock1 == LOW)) {   
       val <<= 1;

         val |= digitalRead(pin4);
             if(val | 0x80) {   // flag bit has reached the top of the byte so we've done 8 iterations
           

           
                     
           Serial.print(val & 0x7F, HEX);
           Serial.println();
           val = 0b00000001;
         }
   
    }
    clock1= clock;
}
24  Topics / Science and Measurement / Re: Reading data at 10 Khz rate on: October 03, 2012, 04:50:12 am
No first 24 bit will be CAAC1F(in HEX) if it is then receive next 96 bits otherwise slide to next bit until it matches the string but the string matching is done on a PC where LabVIEW software is running so my job is to silde it until i get send all 96 bits command from labview

And this code is somewhat working can you take a look at it.
Code:
const int pin2 = 2;
const int pin4 = 4;
int clock;
int clock1;
int val1;
int val2;
int val3;
int val4;
int val5;
int val6;
int val7;
int val8;
byte value =0000000;

void setup()
{
  pinMode(pin2, INPUT);
  
  pinMode(pin4, INPUT);
  
  Serial.begin(2400);
}
void loop()
{
  static byte val  = 0b00000001;

    clock = digitalRead(pin2);
    if ((clock == HIGH) & (clock1 == LOW)) {  
       val <<= 1;
       val1 = digitalRead(pin4);
       val2 = digitalRead(pin4);
       val3 = digitalRead(pin4);
       val4 = digitalRead(pin4);
       val5 = digitalRead(pin4);
       val6 = digitalRead(pin4);
       val7 = digitalRead(pin4);
       val8 = digitalRead(pin4);
             if(val | 0x80) {   // flag bit has reached the top of the byte so we've done 8 iterations
          
           value=(value | (val1<<7));
           value=(value | (val2<<6));
           value=(value | (val3<<5));
           value=(value | (val4<<4));
           value=(value | (val5<<3));
           value=(value | (val6<<2));
           value=(value | (val7<<1));
           value=(value | (val8<<0));
          
          
          
           Serial.print(value & 0xFF, HEX);
           val = 0b00000001;
         }
        
    }
    clock1= clock;
}


And for your questions
1. I need to send them as hex format for labview understanding
2. No
3. No
4. HEX
5. Keep on sending that Data till i receive a command from pc send next 96 bits of data that data also need to in HEX format fro labview understanding.
Thanks in Advance
Niladri  
25  Topics / Science and Measurement / Re: Reading data at 10 Khz rate on: October 03, 2012, 02:34:06 am
Decoding device is under process(We are building our own homemade BCH decoder)
You can say it is filter tuned for 5.5 khz and 3.125 khz and it generates pulses and clock recovery system recover 10 khz clock now output from the 3.125 khz is passed through not gate to get stream of 128 bits(0 and 1) now each positive edge we need to read the value and each nibble we need convert to serial data and send it to pc. AS i said before it is like data acquisition system which can sample at 10 khz rate discrete input
If you have any other inquiry please let me know
Thanks in advance
Niladri     
26  Topics / Science and Measurement / Re: Reading data at 10 Khz rate on: October 02, 2012, 11:07:22 pm
Many thanks to everybody for their response
the Data is coming from a decoding device and it is continuously running for 1-2 hours
I just need to send those data to PC as like serial data because pc cannot read discrete input.   
Thanks in advance
Niladri
27  Topics / Science and Measurement / Re: Reading data at 10 Khz rate on: October 01, 2012, 07:48:41 am
Sorry for initially mentioning that the data is parallel but now it has converted to serial. I have tried using everybody idea(especially Rob) but yet no fruitful result
Code:
const int pin2 = 2;
const int pin4 = 4;
int clock;
int clock1;

void setup()
{
  pinMode(pin2, INPUT);
   
  pinMode(pin4, INPUT);
 
  Serial.begin(9600);
}
void loop()
{
  static byte val  = 0b00001000;

    clock = digitalRead(pin2);
    if ((clock == HIGH) && (clock1 == LOW) {   
       val <<= 1;
       val |= digitalRead(pin2);
       if(val | 0x80) {   // flag bit has reached the top of the byte so we've done 4 iterations
           Serial.print(val & 0x7F, HEX);
           val = 0b00001000;
         }
      clock1 = digitalRead(pin2);   
    }
}
28  Using Arduino / Project Guidance / Re: Changing the I2C adress of arduino on: September 27, 2012, 04:55:34 am
Sorry bit late to post this but this possible (not 5 bit address scheme).
In Wire.begin() if you don't write anything it will take the default address(i,e 127, 0x7F) but if you give any other address which does not conflict with other device it takes that address(if you send like Wire.begin(0x05) and then run the nick gammon scanner sketch making another arduino as master that the one which has been programmed with 0x05 will give the address 0x05. I have the screen shot i will post it some other time. ) 
Thanks everybody for their valuable input
Regards
Niladri
29  Topics / Science and Measurement / Re: Reading data at 10 Khz rate on: September 27, 2012, 01:15:49 am
i have written this code but it is not giving me the hex data which i have given as input.
Any suggestion?
Niladri
Code:
const int pin1 = 2; // the pin where clock will be taken
const int pin2 = 4; // the pin for data input
int count;


void setup()
{
  //  initialize the button pin as a input:
  pinMode(pin1, INPUT);
  //  initialize the button pin as a input:
  pinMode(pin2, INPUT);
  //  Initializing for serial communication
  Serial.begin(9600);
}
void loop()
{
  int clock = digitalRead(pin1); // Reading the clock
   
  if (clock == HIGH) // At each raising edge data should be taken
  {
    int data = digitalRead(pin2); // when a raising edge comes read the data
    count++;
    if(count%4 == 0)
        Serial.print(data, HEX);// Read the data on serial moniter to check logic is right or not
   
  }

30  Topics / Science and Measurement / Re: Reading data at 10 Khz rate on: September 26, 2012, 08:13:04 am
Thanks everyone for their replies
it is 8 bits and no protocol only serial data
Pages: 1 [2] 3