Offline
Newbie
Karma: 0
Posts: 39
Well done is better than well said." --Benjamin Franklin
|
 |
« on: September 26, 2012, 04:10:17 am » |
Hi guys Can arduino Uno read digital data of 10 KHz frequency? Thanks in advance Niladri.
|
|
|
|
|
Logged
|
Thanx & Regards
Niladri
|
|
|
|
Brisbane, Australia
Offline
God Member
Karma: 17
Posts: 812
|
 |
« Reply #1 on: September 26, 2012, 07:26:11 am » |
Hi Niladri
Do you need a serial connection that's 10,000 baud? Then yes, that's possible with Arduino Uno.
Geoff
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 277
Posts: 25537
Solder is electric glue
|
 |
« Reply #2 on: September 26, 2012, 07:46:45 am » |
What form is this data in? Is it serial or parallel? The arduino has a 16MHz processor so 10KHz is slow, however what are you going to do with it! There is not much room to store very much data, less than a few mS at that rate.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 39
Well done is better than well said." --Benjamin Franklin
|
 |
« Reply #3 on: September 26, 2012, 07:48:35 am » |
Thanks for the reply Actually i need to read a clock of 10 khz and each positive going pulse i need to read data. I have already done using NI LabVIEW and its DAQ card but i want a cheaper replacement so was thinking can i use arduino uno or not? Is it possible?? Thanks in advance Niladri.
|
|
|
|
|
Logged
|
Thanx & Regards
Niladri
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 277
Posts: 25537
Solder is electric glue
|
 |
« Reply #4 on: September 26, 2012, 07:51:21 am » |
Yes this sounds like an SPI data protocol, look up how to do that.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 39
Well done is better than well said." --Benjamin Franklin
|
 |
« Reply #5 on: September 26, 2012, 07:53:32 am » |
Data is parallel and i will send the data to the pc with the help of file write i will store it in the pc(A cheap DAQ at 10 KHz )
|
|
|
|
|
Logged
|
Thanx & Regards
Niladri
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 39
Well done is better than well said." --Benjamin Franklin
|
 |
« Reply #6 on: September 26, 2012, 07:56:09 am » |
No sir it is not SPI protocol it is more of a Simple Discrete to Serial Converter at 10 KHz clock speed. I am aware of SPI protocol. I have already implemented SPI protocol in arduino.
|
|
|
|
|
Logged
|
Thanx & Regards
Niladri
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 277
Posts: 25537
Solder is electric glue
|
 |
« Reply #7 on: September 26, 2012, 07:57:47 am » |
Ok we are in blood out of a stone mode. How many bits parallel? There is a complication in that there is not a free 8 bit port on the arduino so you would have to read them in prices and put them together into bytes to send serially. Will you need a protocol , or can you just stream it out?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 39
Well done is better than well said." --Benjamin Franklin
|
 |
« Reply #8 on: September 26, 2012, 08:13:04 am » |
Thanks everyone for their replies it is 8 bits and no protocol only serial data
|
|
|
|
|
Logged
|
Thanx & Regards
Niladri
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 39
Well done is better than well said." --Benjamin Franklin
|
 |
« Reply #9 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 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 } }
|
|
|
|
|
Logged
|
Thanx & Regards
Niladri
|
|
|
|
Brisbane, Australia
Offline
God Member
Karma: 17
Posts: 812
|
 |
« Reply #10 on: September 27, 2012, 01:49:23 am » |
Hi, You mentioned the data was parallel earlier, but here you're only allowing for one data line, so I'll presume you meant the data was purely serial. Every time loop() is run, the variable data is recreated losing the previous information. So while I can see your intention is to read the data line for 4 pulses then output, the only thing you'll ever have to output is the value of the most recent digitalRead (either 0 or 1 being LOW or HIGH) stored in the variable data. So if you're going to construct the data variable a bit at a time, that variable needs to have a global scope, same as your count variable, and store the bit that you read in the right position within it (via bitset() maybe, or some bitwise math regardless) each iteration of loop() then discard the content on the 4th pass after printing. Hope that makes sense. Also while your comment suggests this next test is for a rising edge... if (clock == HIGH) // At each raising edge data should be taken in actual case there's nothing to stop it reading the data line multiple times for any one HIGH pulse of the clock, presuming loop() executes fast enough. Also, of course there's nothing there to stop it missing out on data if your loop() takes too long, but that's unlikely in this scenario I think. If you truly need it to be on the rising edge, you might consider implementing this using interrupts; alternatively use an additional check that the clock line is HIGH, but last time through was LOW, and only act when that's the case. Cheers ! Geoff
|
|
|
|
|
Logged
|
|
|
|
|
nr Bundaberg, Australia
Online
Tesla Member
Karma: 72
Posts: 6837
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #11 on: September 27, 2012, 05:31:00 am » |
How about you verify the number of bits you need. According to your code it's 4. There are faults in your code as strykeroz has commented on, but for a start to get 4 bits you need to accumulate the results of 4 digitalRead()s, for example loop () { static byte val = 0b00001000;
if (rising_edge_on_clock_pin) { // you figure out how to detect this 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; } } }
______ Rob
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 277
Posts: 25537
Solder is electric glue
|
 |
« Reply #12 on: September 27, 2012, 08:49:22 am » |
Yes Rob but the big thing he is mixed up about is if the data is serial or parallel. He has said in one post that is was parallel so he needs to read more than one pin and amalgamates the results into one byte before sending it. This might be best doing two reads direct from two ports and oring them together. Choice of the right pins to wire the data to is crucial to making this efficient.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 39
Well done is better than well said." --Benjamin Franklin
|
 |
« Reply #13 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 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); } }
|
|
|
|
|
Logged
|
Thanx & Regards
Niladri
|
|
|
|
Brisbane, Australia
Offline
God Member
Karma: 17
Posts: 812
|
 |
« Reply #14 on: October 01, 2012, 08:34:43 am » |
Hi Two obvious things I think to look at - firstly clock1 isn't initialised, so first pass through it won't have a reliable value. You can fix that in your declaration: int clock1 = 0; And the other part is you don't want to set clock1 at the end of the loop to whatever the digital pin value is, but rather what clock was. Like this: clock1 = digitalRead(pin2); // becomes clock1 = clock; Just two thoughts to start you off  Geoff
|
|
|
|
|
Logged
|
|
|
|
|
|