Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

CR 1000 with SDM-CAN


Funkster Apr 5, 2012 01:16 PM

Hey all,
we want to retrieve data with a CR 1000 from a CAN based network.
We are using a SDM-CAN interface.
The internal jumpers from the SDM-CAN are set as follows:

-Isolated Mode = Enable
-DC-DC = On
-120R = in
-TX = Enable

The SDM- address is 0

Our CAN Network has the following parameters:
Only one message
-Data type = singed integer
-byte order = Motorola
-byte length = 2 Byte
-Identifier = 104 (11bit)
-start bit = 7
-bit rate = 250 Kbyte/sec
The A/D Changer, which is connected to the network is terminated, has a scan rate of 1Hz and is fed with 5V.

Here is our used CRBasic program:

'Set Scan Rate

Const Period=1

Const P_Units=2

' \ \ \ \ \ \ \ \ \ \ \ \ CANBUS Constants / / / / / / / / / / / /

'------------------------- Physical Network Parameters ------------

'Set SDM-CAN to 250K

Const TQUANT=4

Const TSEG1=5

Const TSEG2=2

'------------------------ Data Frame Parameters -------------------

'___________________ Canbus Block1_____________________

'Collect and retrieve 16-bit data value

'Data Type 1, signed integer, least significant byte first


Const ADDR1=0 'Address of SDM-CAN module

Const DTYPE1=4 'Data values to collect

Const STBIT1=7 'Start position in data frame

Const NBITS1=16 'Number of bits per value

Const NVALS1=1 'Number of values

Const CMULT1=0.000423868 'Multiplier

Const COSET1=0 'Offset

' \ \ \ \ \ \ \ \ \ \ \ \ Aliases and other Variables / / / / / / / /
Public test


'\\\\\\\\\\\\\\\\\\\\\\\\\
DataTable (Tab_1sec,1,1)
DataInterval (0,1,Sec,10)
Sample (1,test,FP2)

EndTable

' \ \ \ \ \ \ \ \ \ \ \ \ \ PROGRAM / / / / / / / / / / / / / / / / /

BeginProg

Scan(PERIOD,P_UNITS,0,0)

'____________________ CAN Blocks_______________________

'Retrieve Data from CAN-bus network

SDMCAN (test, ADDR1, TQUANT, TSEG1, TSEG2, -104, DTYPE1, STBIT1, NBITS1, NVALS1, CMULT1, COSET1)


CallTable (Tab_1sec)
NextScan

EndProg

It dosn't work with this settings. Have you any idea what is wrong?
Let me know if you need more information.

Thanks for your help...

funkster

* Last updated by: Funkster on 4/5/2012 @ 7:11 AM *


GTProdMgr Apr 5, 2012 05:02 PM

Hello Funkster,

I have looked at the SDM-CAN Helper software and have the following recommendations.

You indicate that your 120 Ohm termination jumper on the SDM-CAN is set to "IN", but the helper recommends that it be "OUT".

In your program, you have this
Const DTYPE1=4 'Data values to collect
Const STBIT1=7 'Start position in data frame

But it should be this :
Const DTYPE1=3 'Signed Integer,Most Signif. Byte 1st(Motorola)
Const STBIT1=49 'Start position in data frame

I'm assuming that your start bit of "7" was given by the .DBC file or similar document.

I would try those three items first.

Also, I would recommend that if you have the RTDAQ software
that you download the SDM-CAN Helper (free):

http://www.campbellsci.com/canhelper

The Single Signal Calculator provided with the SDM-CAN Helper was able to easily show that a Start bit of 49
is needed, and also provided this graphical representation
of the bit layout of the CAN data frame:

CAN Buffer Frame Map (Not Shifted)
--------------------------------------------------------------------
Incoming Bit: [OrigBit (Byte,Offset)][BuffFW][BuffBW] MsgName | DataType | {MSBit or LSBit} | {PckLst StartBit}
-- Byte 0 --
1: [7 (0,7)] [64] [-1] TestSignal | MSBSInt | MSBit
2: [6 (0,6)] [63] [-2] TestSignal | MSBSInt
3: [5 (0,5)] [62] [-3] TestSignal | MSBSInt
4: [4 (0,4)] [61] [-4] TestSignal | MSBSInt
5: [3 (0,3)] [60] [-5] TestSignal | MSBSInt
6: [2 (0,2)] [59] [-6] TestSignal | MSBSInt
7: [1 (0,1)] [58] [-7] TestSignal | MSBSInt
8: [0 (0,0)] [57] [-8] TestSignal | MSBSInt
-- (END) Byte 0 --
-- Byte 1 --
9: [15 (1,7)] [56] [-9] TestSignal | MSBSInt
10: [14 (1,6)] [55] [-10] TestSignal | MSBSInt
11: [13 (1,5)] [54] [-11] TestSignal | MSBSInt
12: [12 (1,4)] [53] [-12] TestSignal | MSBSInt
13: [11 (1,3)] [52] [-13] TestSignal | MSBSInt
14: [10 (1,2)] [51] [-14] TestSignal | MSBSInt
15: [9 (1,1)] [50] [-15] TestSignal | MSBSInt
16: [8 (1,0)] [49] [-16] TestSignal | MSBSInt | LSBit | PCKStartBit
-- (END) Byte 1 --


GTProdMgr Apr 5, 2012 06:01 PM

Let me explain how I got from a given start bit of 7
to the result of 49 that needs to be used with the
SDMCAN instruction in the CRBasic Program.

You can see in the frame map, that your TestSignal, being
two bytes long, takes up the first 16 bits in the frame.

The left-most reference shows 1,2,3,4...,15,16 for those
bits. Since this item is Motorola byte order, the Most significant byte is given first. The Most significant
bit is in position 1, and the least significant bit
is in position 16 (look for MSBit and LSBit).

The SDMCAN instruction in CRBasic needs to have the least significant bit as given by the SDM-CAN's numbering scheme.
The column that numbers as 64,63,62,61,...,50,49 is the
scheme used by the SDM-CAN. So you can see that the SDM-CAN will refer to position 16 as bit 49.

The column that numbers as 7,6,5,4...11,10,9,8 is the .DBC (Can Database, Vector) numbering scheme. .DBC refers to its start bit as the most significant bit. So in this case position 1 maps to 7 for the start bit in the .DBC world.

The reason why we have made the SDM-CAN Helper available for free to RTDAQ users was to help out users so they don't have to go through calculations like this each time they want to isolate and use a CAN signal on their network. The Single-Signal Calculator and the DBC to Picklist converter were designed to help users through this process in a simpler and more reliable way.


GTProdMgr Apr 5, 2012 06:42 PM

There is one other factor to consider -- and that is the size of the CAN Message Frame. The SDM-CAN will shift a frame "over" when its number of bytes is less than 8.

The largest frame size possible is 8 bytes (64 bits). With your signal of 2 bytes, there is a possibility that the frame size is as small as 2. However, all sizes from 2 to 8 are possible. Your signal could be only one of several that are encoded into the frame (even though you are only interested in the particular value you describe).

The SDM-CAN start bit value of 49 corresponds to
a frame size of 8. The value of 1 corresponds
to a frame size of 2. Please use the chart below
to find the right start-bit for your frame size:

Message Frame Size (Bytes) Recommended Start Bit
--------------------------- ----------------------
8 49
7 41
6 33
5 25
4 17
3 9
2 1


Funkster Apr 10, 2012 07:12 AM

Hello GTProdMgr,
we are using LoggerNet 4.1, so we don’t have the possibility to use the SDM-Can helper.
With your proposed settings I only get NAN. Which kind of datatype should I choose in the variables declaration? At the moment I use the 4 Byte IEEE4 Floating point Format.

Thanks for your support.

Regards Funkster


GTProdMgr Apr 10, 2012 10:01 PM

Hello Funkster,

I'm recommending that you contact your local
Campbell Scientific support contact for further
help. I'm providing some more guidance here,
but I feel you will be better served with an
official support exchange (via email or telephone).

Once your issue is resolved, we can see to it that
the resolution is posted here for the benefit of
future searchers.

Thanks.


------
You mentioned that you need to capture a 4-byte
IEEE4 floating point value. In your original
post, you were trying to capture a 2 byte signed
integer (Motorola/MSB first).

I recommended a data type of 3 for the two-byte
signed integer (Const DTYPE1=3, then DTYPE1 is
used as the DataType argument of the SDMCAN
instruction in your program).

If you look at the SDMCAN help topic for the
CRBasic Editor, you can see the following data
type options :

1 : Retrieve data; unsigned integer, most significant byte first
2 : Retrieve data; unsigned integer, least significant byte first
3 : Retrieve data; signed integer, most significant byte first
4 : Retrieve data; signed integer, least significant byte first
5 : Retrieve data; 4-byte IEEE floating point number;
most significant byte first
6 : Retrieve data; 4-byte IEEE floating point number;
least significant byte first

So, if the IEEE4 value you seek is Motorola/MSB, then
you would choose a value of 5 for the Data Type. If
it is Intel order (LSB), you would choose 6. However,
now the number of bits needs to be set to 32 to accommodate
all 4 bytes of the floating point value. Now we need
to know what your frame size is (8,7,6,5, or 4 bytes).

For a frame size of 8, the SDMCAN start bit is 33, for 7
it would be 25, for 6 it would be 17, for 5 it is 9, and
for 4, it would be 1. If you don't know your frame size
you will have to try out all five of those values in
succession.

This assumes that the start bit in the .DBC world is
given as 7 (as you indicated in your original post).

All of this can be surmised from a .DBC file. Do you have
a .DBC file or fragment that you could send to us ? We
can convert that .DBC to a picklist usable by the
CRBAsic editor by using our SDM-CAN Helper. If you will
be doing this kind of work frequently, it will probably
be worthwhile for you to purchase RTDAQ and get the
SDM-CAN Helper.

We are also making the assumption here that your CAN
network is set up to constantly broadcast the value you
are trying to capture. Is that correct ? For some values
on a CAN network, you have to issue a request for the value
first before you can expect the response back. If that
is the case, your program will require more code to issue
the request and then listen for the response.


Funkster Apr 12, 2012 06:16 AM

Hey GTProdMgr,
sry I expressed my self too unclearly. We want to collect a 2 byte signed Integer (Motorola) from the CAN Network. In CRBasic I have declared the variable, who we want to collect from the CAN Network, as a 4 Byte IEEE Floating Point.

We are also making the assumption here that your CAN
network is set up to constantly broadcast the value you
are trying to capture. Is that correct ?


Thats Right!
After my knowledge we doesn’t need a “ Handshake” or something like this.

I have uploaded the .dbc file to Uploaded.to. Here is the Link:
http://ul.to/li93e1o5
Or you give me your email address, and I will send you the file.

Thanks allot. Our local Campbell Support isn’t as well as I wish. They can’t help me therefore I have posted my problem here.

Thanks a lot for our help!!

Best regards Funkster

* Last updated by: Funkster on 4/12/2012 @ 12:18 AM *


GTProdMgr Apr 12, 2012 05:28 PM

The declaration in your program of "Public test" will ensure that the 2-byte signed integer will be stored in the "test" variable as IEEE4. When you declare a variable in CRBasic without specifying its data type, it defaults to Float/IEEE4. The SDMCAN instruction knows that "test" is IEEE4 and is the destination for the retrieved result, so it will do that conversion automatically.

Your DBC file showed a frame size of 2 bytes and a
DBC start bit of 7, so based on the previous table I
gave you (shown below) you should use the SDM-CAN start
bit of 1 (STBIT1=1).

Message Frame Size (Bytes) Recommended Start Bit
--------------------------- ----------------------
8 ----------- 49
7 ----------- 41
6 ----------- 33
5 ----------- 25
4 ----------- 17
3 ----------- 9
2 ----------- 1

Everything else from my original response should be used:
DType1 = 3, NBITS1 = 16, etc. Please confirm that your 120 Ohm termination jumper is set as "OUT".

I've also posted the PCK file below as given by the DBC conversion program. Put it into a .PCK file, and you can retrieve it from within the CRBasic Editor. (Right click on the SDMCAN instruction and press the "Select .PCK Values" button, then you can browse to the .PCK file.)

----------
PCKCRBV1
Description=RxCANIdent,IDBitSize,DataType,StartBit,Numbits,Alias,Mult,Offset,Units
Botschaft104_Kanal01=&H68,11,3,1,16,Kanal01,0.000423868,0,V
----------


Funkster May 2, 2012 06:27 AM

Thanks for your help!
It works. But i have to set the intern switches to 0101.

Best regards
Funkster

* Last updated by: Funkster on 5/2/2012 @ 12:30 AM *


GTProdMgr May 2, 2012 09:02 PM

Great ! I'm glad it worked for you.

I'm assuming that your internal switch settings of
0101 would mean that the 120R jumper setting is "IN" instead
of "OUT" as I recommended before, and that the TX jumper setting is "Enabled". Is that correct ?


CANMan May 4, 2012 10:58 PM

I think that Funkster is refering to the SDM-CAN internal software switches and not the hardware jumpers. 0101 would be the ABCD digit code where B=1 is mark old data with NaN, C=0 is disable io interupts, and D=1 is CAN chip in operation mode of one shot transmission mode with no retransmission if error or arbitration loss.


CANMan May 5, 2012 01:37 AM

Hi Funkster and GTProdMgr.

I wanted to make sure you were succesful in acquiring the 4 each 2 byte motorola format signed integers from your Msg0x104 CAN frame. If I understand correctly your CAN frame was packaged as:

64w63w62w61w60w59w58w57w
56w55w54w53w52w51w50w49w
48x47x46x45x44x43x42x41x
40x39x38x37x36x35x34x33x
32y31y30y29y28y27y26y25y
24y23y22y21y20y19y18y17y
16z15z14z13z12z11z10z09z
08z07z06z05z04z03z02z01z

... where w, x, y, and z mark the bit locations of your 4 each 2 byte signed integers with the bits numbered per the the SDM-CAN index system.

What did you end up using for your DataType and StartBit SDM-CAN decoding parameters for w, x, y, and z? I was thinking you ended up using DataType=3=MostSignificantByteFirst, NumberOfBits=16 and the following SDM-CAN based start bits for the four values.
w=01
x=17
y=33
z=49
per the SDM-CAN start bit rule of "Least significant bit of least significant byte".

I would think that the following CRBasic program would work for you to decode/acquire the four signals from the frame. Can you please test it out for me to verify that is what worked?

Const MsgID0x104=-104'11Bit identifier
Public Msg0x104(4) As Float
BeginProg
Scan(1,Sec,0,0)
SDMCAN(Msg0x104(),0,4,5,2,-104,3,1,16,4,1.0,0.0)
NextScan
EndProg

CANMan.


CANMan May 5, 2012 01:46 AM

I noticed I should have put aliases in the test program so that you can identify the four signals in the frame.

Public Msg0x104(4) As Float
Alias Msg0x104(1)=Signal_x
Alias Msg0x104(2)=Signal_w
Alias Msg0x104(3)=Signal_y
Alias Msg0x104(4)=Signal_z
BeginProg
Scan(1,Sec,0,0)
SDMCAN(Msg0x104(),0,4,5,2,-104,3,1,16,4,1.0,0.0)
NextScan
EndProg

'CANMan


CANMan May 5, 2012 01:52 AM

Whoops the manual says that the SDM-CAN repeats the decode pattern from right to left therefore destination field (1) would be z, (2) y, (3) x, and (4) w.

Public Msg0x104(4) As Float
Alias Msg0x104(1)=Signal_z
Alias Msg0x104(2)=Signal_y
Alias Msg0x104(3)=Signal_x
Alias Msg0x104(4)=Signal_w
BeginProg
Scan(1,Sec,0,0)
SDMCAN(Msg0x104(),0,4,5,2,-104,3,1,16,4,1.0,0.0)
NextScan
EndProg

Let me know if that works or not.

'CANMan


CANMan May 5, 2012 02:33 AM

I am not doing so well in my first participation on the forum. I messed up my determination of the SDM-CAN start bits for signals w, x, y, and z. Here is a ReDo of the frame map, start bits, and CRBasic program.

'CAN Msg0x104 frame layout:
'{
'64w63w62w61w60w59w58w57w
'56w55w54w53w52w51w50w49w
'48x47x46x45x44x43x42x41x
'40x39x38x37x36x35x34x33x
'32y31y30y29y28y27y26y25y
'24y23y22y21y20y19y18y17y
'16z15z14z13z12z11z10z09z
'08z07z06z05z04z03z02z01z
'...
'Where w, x, y, and z signals are Motorola format 2 byte signed integers.
'SDMCANDataType=3, Number of bits=16.
'The SDM-CAN start bit is least significant bit of least significant byte.
'So SDM-CAN start bits for the signals would be w=49, x=33, y=17, &z=01.
'Run decode pattern 4 times starting on StartBit=1.
'}

Public Msg0x104(4) As Float
Alias Msg0x104(1)=Signal_z
Alias Msg0x104(2)=Signal_y
Alias Msg0x104(3)=Signal_x
Alias Msg0x104(4)=Signal_w
BeginProg
Scan(1,Sec,0,0)
SDMCAN(Msg0x104(),0,4,5,2,-104,3,1,16,4,1.0,0.0)
NextScan
EndProg

'CANMan

Log in or register to post/reply in the forum.