CAN Controller Speed

"Clemens Dungl" <[email protected]> Wed, 30 Jun 2004 19:22:27 +0200
Newsgroups gmane.comp.hardware.microcontrollers.tini
Message-ID <001001c45ec6$d39f8940$060010ac@laptop>
Hello Everybody,
i am using the TINI Board (Dalsemi TINI 87-2 SKT Rev C.) and the Socket
Rev. D with the Software TINI 1.12 for my final project in Spain. I
soldered the Phillips PCA82C251 CAN controller to the board to use the
CAN bus. 

I got a can source which supplies a stream with 1 Mbps. In the TINI API
read that the maximum speed is 125 kbps.  The Datasheet of the CAN
controller(PCA82C251) tells "High speed (up to 1 Mbaud)" so it should be
possible.
Can you tell me how to achieve this bit rate of 1Mbps?

Now I am experimenting with another CAN source which provides 125 kbps.
This source can be set up to send repeatedly for instance 100 times with
a delays of 100ms. In this case I receive the messages correct and the I
send it to the socket. If I set up delay time to 10ms or 0ms I just
receive ca. 67 messages of 100 without any RX error count. 
I tried to change the buffer to 75 because 255 did not work on TINI, to
use the polling, and many other things.
How can I make a commitment to be sure to receive all the messages??? 

Any other advices about the program?


Thank you in advance, 

Clemens 
(Barcelona)


Attached the source code:
**********************************************************************
// Compiliert auf Laptop
// with optimized reed process

import com.dalsemi.comm.*;   // modules.jar CanFrame.class,CanBus.class
import com.dalsemi.system.*;
import java.net.*;
import java.io.*;

public class canreceive4
{
    /* 125Kbit/s with crystal of 18.432MHz */
    static final int CAN_DIVISOR = 7;
    static final int CAN_TSEG1 = 13;
    static final int CAN_TSEG2 = 7;
    static final int CAN_SJW = 1;
    static final byte CANBUSNUM = CanBus.CANBUS0;
//    static final byte CANBUSNUM = CanBus.CANBUS1;

     static final int MAXCOUNT = 100;

    static final boolean dopassive = false;  //Starts up this CAN
controller, but doesn't connect CAN transmit to the bus. Become a quiet
listener on the bus. All critical timing parameters must already be set.
Message centers remain intact.

    static void readCAN() throws Exception // reads CAN and call the
Send to Socket method
    {

      //*************************************************

       int port = 1502;
     String server = "147.83.13.233";
     Socket socket = null;
     String lineToBeSent;
     InputStream ins;
     PrintWriter output;
     int ERROR = 1;
     StringBuffer buffer = new StringBuffer();
     String nachricht="";
   System.out.println("Sending Frame to Socket");

   // connect to server Ethernet
   try {
           socket = new Socket(server, port);      // socket opening
with name socket
           System.out.println("Connected with server : " + server + " at
Port" + port);
        }

       catch (UnknownHostException e) {
           System.out.println(e);
           System.exit(ERROR);
       }
       catch (IOException e) {
           System.out.println(e);
           System.exit(ERROR);
       }


      // Initializise CAN *************************
        final int DUMPCOUNT = 1;
        long start,stop;

        CanBus a = new CanBus(CANBUSNUM);       //canbus opening with
name "a"
        a.setBaudRatePrescaler(CAN_DIVISOR);    // the following
parameters sets the speed to 125 kbps
        a.setTSEG1(CAN_TSEG1);
        a.setTSEG2(CAN_TSEG2);
        a.setSynchronizationJumpWidth(CAN_SJW);

        a.setReceiveQueueLimit(75); //mit 75 best results
        a.setTransmitQueueLimit(1); //Sets transmit queue frame limit.
If the limit is set to zero, writes will block until frame is
transmitted, or bus error. Maximum limit is 255 frames.

        System.out.println("Frames available to read:
"+a.receiveFramesAvailable());

        a.enableController();  // haut nicht hin
        a.setMessageCenterRXMode(1); // Set message center one to
receive
        a.setMessageCenterMessageIDMaskEnable(1,false); // Set message
center one to not use mask filtering
        a.set11BitMessageCenterArbitrationID(1,0x55F6575C); //
(1,075C)Sets an 11 Bit Arbitration ID for a message center. When this
value matches an incoming frame ID subject to the Global ID Mask or
Message Center 15 Mask, the incoming frame will be received.

        // Set message center one to allow reception of messages.
        a.enableMessageCenter(1);

        CanFrame frame = new CanFrame(); // Create the frame for
recieve() to fill

        System.out.println("Continous Receive");
        int count = 1;
        int endcount = MAXCOUNT;
        int firstpacket = 0;
        int rxerror = 0;
        int txerror = 0;
        int q =0;  //receive Queue
        start = TINIOS.uptimeMillis();    // store the startTime in the
variable Start
        boolean error = false;
        int j;
        System.out.println ("no error - wait for Package " + count );
        while ((count < endcount) )  //!entfernt count < endcount
        {
            a.receivePoll(frame); //Receives a CAN data frame. This
method blocks until a frame is received.
         //  a.autoAnswerRemoteFrameRequest(1,0x55F6575C, temp);
            count++;
            nachricht = ""; // clear message
           // System.out.print ("for   " );
            for (int i = 0;i < frame.length;i++){   // adds new
nachricht to existing nachricht
                  nachricht = nachricht + new
String(Integer.toHexString(frame.data[i] & 0xFF)+" ");
                }
            buffer = buffer.append(nachricht);  // appends String to
buffer

       // close CAN ***********
        }
        q = a.receiveFramesAvailable(); // trows the number (int) frames
in receive queue
        System.out.print (q + " in Queue  " );

      while ((q > 0) )  //empty buffer************
       {
           a.receive(frame); //Receives a CAN data frame. This method
blocks until a frame is received.
           nachricht = ""; // clear message
           for (int i = 0;i < frame.length;i++){   // adds new nachricht
to existing nachricht
                 nachricht = nachricht + new
String(Integer.toHexString(frame.data[i] & 0xFF)+" ");
               }
           buffer = buffer.append(nachricht);  // appends String to
buffer
           q = a.receiveFramesAvailable(); // trows the number (int)
frames in receive queue
      }
      System.out.print (q + " after empty " );

        System.out.println ();
        System.out.println (count + " Pagages received             " + q
+ " Frames in Queue.");
        rxerror  = a.getRXErrorCount();   // gets errors of transmitted
packages

        //a.sendFrame(frame); // sends a frame to CAN

        txerror  = a.getTXErrorCount();
        System.out.println (rxerror + " Rxerror     " + txerror + "
Txerror");
       // close CAN ***************************
        stop = TINIOS.uptimeMillis();
        System.out.println("Completion time: "+(stop-start));
        System.out.println(start+":"+stop);
        System.out.println("Exited after "+(count-firstpacket)+"
iterations");

        a.close();  // closes CAN connection

        // close Socket**********************
        try {
          //  write
          output = new PrintWriter(socket.getOutputStream(),true);
          System.out.println("here start the loop...");
          System.out.println(" frame.data: " + frame.data + "length: " +
          frame.length + "Nachricht: " + nachricht); // drucke auf
TiniSchirm
       //   nachricht = new String(buffer.toString());
          output.print(buffer.toString()); // write to socket

        }
       catch (IOException e) {System.out.println(e);} //output
// close
       try {
           socket.close();
       }
       catch (IOException e) { System.out.println(e); }

//***************************************
}

    static void main(String args[])
    {
      while(true)
      {
      try
        {

           if (TINIOS.isCurrentTaskInit())
                Debug.setDefaultStreams();

            System.out.println("CAN Receive tester");

            readCAN();

            System.out.println("Normal Exit");
        }
        catch (Throwable e)
        {
            System.out.println("Exception");
            System.out.println(e);
        }
      }
      }
}



_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini