0
Offline
Newbie
Karma: 0
Posts: 22
Arduino rocks
|
 |
« on: September 26, 2010, 03:08:57 am » |
I am trying to interface a digital linear gauge to a Serio. The gauge is a Ono Sokki http://www.onosokki.net/PDFs/Manual%20%20EG225a.pdfI think the format is the same as mitutoyo. I found this code for reading digital calipers, I am thinking the next step is reworking this code to read from the gauge. Does anyone have any advice? //Simple Digital Calliper Reader
// Pin Declarations int dataIn = 11; int clockIn = 12;
// Variables int clock = 1; int lastClock = 1; unsigned long time = 0; unsigned long timeStart = 0; int out = 0;
void setup() { // Pin Set Up pinMode(dataIn, INPUT); pinMode(clockIn, INPUT);
Serial.begin(115200); Serial.println("Ready: "); }
void loop(){
lastClock = clock; clock = digitalRead(clockIn);
if (lastClock == 1 && clock == 0){ out = digitalRead(dataIn)+digitalRead(dataIn)+digitalRead(dataIn); // Tripple sampling to remove glitches if((micros() - time) > 800){ Serial.println(" "); } else if((micros() - time) > 400){ Serial.print(" "); }
if (out > 1){ Serial.print("1"); } else{ Serial.print("0"); } Serial.print(","); time = micros(); } }
|
|
|
|
« Last Edit: September 26, 2010, 02:01:33 pm by schmidtjts »
|
Logged
|
|
|
|
|
Central Europe
Offline
Edison Member
Karma: 5
Posts: 1220
Use the Source, Luke.
|
 |
« Reply #1 on: September 26, 2010, 03:19:51 am » |
What do you expect to achieve, except annoy people, by posting the same message in 3 forums? Also, if you post code, please use the # button on the icon bar above. That makes your message a lot more readable. Does anyone have any advice? The main advice is to ask specific questions if you want specific answers. Also, it would be basic courtesy that you try out your program to see what works before throwing it out to the community to do the debugging and checking its validity. Have fun, Korman
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 22
Arduino rocks
|
 |
« Reply #2 on: September 26, 2010, 01:33:51 pm » |
"before throwing it out to the community to do the debugging and checking its validity."
It was not my goal to have anyone do debigging, I was asking for advice as to whether the general direction I am taking is reasonable or if I am off track.
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 277
Posts: 25553
Solder is electric glue
|
 |
« Reply #3 on: September 26, 2010, 01:54:23 pm » |
It was not my goal to have anyone do debigging, Is that about reducing the code size then? 
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 22
Arduino rocks
|
 |
« Reply #4 on: September 26, 2010, 01:58:37 pm » |
Good one, I meant debugging.
I am so clueless at this point I am just hoping someone will say, either,,
"yes, you can probably use that code concept as a foundation, keep going"
or
"no, that approach is totaly wrong"
or
'uhhhh, these type of harware are not compatible find another way to do it"
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 277
Posts: 25553
Solder is electric glue
|
 |
« Reply #5 on: September 26, 2010, 02:44:12 pm » |
OK then:- out = digitalRead(dataIn)+digitalRead(dataIn)+digitalRead(dataIn); // Tripple sampling to remove glitches
That line is totally wrong. You are doing an arithmetic operation on logical variables, what do you hope it will do? It certainly won't debounce anything. Why do you want to debounce the input anyway, it's coming from an instrument why wold it have bad edges?
Note you are also printing a lot in a time critical routine, that will slow you down and you will miss stuff. But more importantly as you have the hardware and I don't, what does it do when you run it?
|
|
|
|
« Last Edit: September 26, 2010, 02:44:58 pm by Grumpy_Mike »
|
Logged
|
|
|
|
|
UK
Offline
Faraday Member
Karma: 15
Posts: 2852
Gorm deficient
|
 |
« Reply #6 on: September 26, 2010, 02:59:10 pm » |
If it's really RS232, I'd be asking what you're doing to limit input voltages above and below the AVR's supply rails.
|
|
|
|
|
Logged
|
Per Arduino ad Astra
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 22
Arduino rocks
|
 |
« Reply #7 on: September 26, 2010, 03:22:24 pm » |
out = digitalRead(dataIn)+digitalRead(dataIn)+digitalRead(dataIn); // Tripple sampling to remove glitches
This is the code as I found it, I couldn't figure out why it was sampled three times either, I guessed there must be something in the hardware that causes a reason for it. what does it do when you run it?
I am waiting for a cable to arrive tomorrow, unfortunalty my boss thinks (expects) that I will plug the cable in and it will work.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 22
Arduino rocks
|
 |
« Reply #8 on: September 26, 2010, 03:28:20 pm » |
If it's really RS232, I'd be asking what you're doing to limit input voltages above and below the AVR's supply rails. Sorry, I should probably know what that is about but I don't. Do you mean resistor pull up? I will search around and see if I can figure it out.
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 277
Posts: 25553
Solder is electric glue
|
 |
« Reply #9 on: September 26, 2010, 03:38:50 pm » |
I guessed there must be something in the hardware that causes a reason for it. No not at all, I know hardware and this line is just wrong. If it's really RS232, I'd be asking what you're doing to limit input voltages above and below the AVR's supply rails The answer is that it is absolutely nothing to do with RS232. From the data sheet posted it is a 48 bit serial stream synchronised to a clock. I am waiting for a cable to arrive tomorrow, And assuming one end goes in the gauge what will you do with the other end? unfortunalty my boss thinks (expects) that I will plug the cable in and it will work. But you haven't even begun to write any code, all that code will do is tell you of the occasional logic level of the input, it's not fast enough to show you the whole binary stream let alone get numbers out of it.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 22
Arduino rocks
|
 |
« Reply #10 on: September 26, 2010, 03:52:32 pm » |
Thanks so much for your input, maybe I should explain better my task. We are making a machine to measure camshafts for racing engines. This is way out of my area of knowledge but the job was given to me because I can code in VB (mostly copy and paste stuff) and no one else can do even that. I was given three pieces of hardware: A SerIO from sparkfun. http://www.sparkfun.com/commerce/product_info.php?products_id=9521An Accucoder rotary encoder (incremental) A linear digital gauge I was able to find code examples and got the rotary encoder working and can display the output in a VB application. For me that is a big accomplishment. I posted what is working here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1185064568Now I need to do the same with this linear gauge. This linear gauge appears to be a much more difficlt problem because it sends the information in time based signals (that is about as much as I understand right now). I can usually figure stuff out by foraging Google but at this point I wonder if this is a reasonable approach I am taking or if I would be smarter to just get a SmartCable: http://www.spcanywhere.com/smartcable.html
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 277
Posts: 25553
Solder is electric glue
|
 |
« Reply #11 on: September 26, 2010, 04:20:25 pm » |
but at this point I wonder if this is a reasonable approach I am taking or if I would be smarter to just get a SmartCable: Defiantly. I have just been having a go at trying to write something but it is difficult to synchronise the data. Once you do know where you are in the stream it is relatively easy to get the data in. But it comes out continuously so you never see the start. If I had the hardware then it might be easy to see if giving it a reset or a mode change allowed easy synchronisation but it is hard to tell. You are way out of your depth here so go for the easy option.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 22
Arduino rocks
|
 |
« Reply #12 on: September 26, 2010, 04:39:27 pm » |
You are way out of your depth here so go for the easy option. Thanks, that's what I wanted to know. I will just get the smartcable and be done with it. That should save about a weeks wasted time.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 17
Fwd & Rev Eng
|
 |
« Reply #13 on: September 27, 2010, 02:29:41 am » |
Isn't the sequence 0000 [end of one value data] --> 1111 [start of data] --> 1110 [start of value] --> MS decimal digit (value < 1010) unique in the stream?
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 277
Posts: 25553
Solder is electric glue
|
 |
« Reply #14 on: September 27, 2010, 02:40:03 am » |
Isn't the sequence ............. unique in the stream Yes it is from a nibble point of view but I am not sure if it is from a bit point of view. You need to consider the bit sequence in order to synchronise. So that is you need to consider what happens when you have the end of one nibble and the start of the next. However, you could be right. But in the context of the question the original poster knows so little about programming that trying to talk him through this process is not going to be an easy matter. This is because there are other considerations, like transferring the data to the PC and sorting out exactly what frame he has (I understand there are four different types but the data sheet doesn't make it clear) To be pragmatic what he is really after is a result rather than the learning experience. By the way MS decimal digit (value < 1010) is not the biggest value it is 1001 = (9 is the largest digit).
|
|
|
|
« Last Edit: September 27, 2010, 02:42:50 am by Grumpy_Mike »
|
Logged
|
|
|
|
|
|