dsPIC and internal CAN

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
beambase
Posts: 94
Joined: Wed Jul 29, 2009 5:15 pm
Has thanked: 6 times
Been thanked: 8 times
Contact:

dsPIC and internal CAN

Post by beambase »

Hello
I've beeen working on a project that uses the internal CAN controller on a 30F6012A chip and there seams to be some problems.

The problem is that it seam that it is not possible to populate the frames with any data. Regardless of what I put in to the TxData macro, All I get out is 00 as a values. It doesn't matter if I use fixed values or vaiables.
Looking at the CAN trafic with a CANBUS analyser I get errors after the second frame. It doesnt matter what I set the DLC to.

Attached is a very simple program that should produce some data output but the CAN analyser says that the values is 00 even when using just 1 DLC.

Looking at the traffic with a logic analyzer I detext errors after thefirst frame. No CRC can be detected. Does anyone has any experience with the CAN component in dsPIC?
Attachments
6012ACantest1.fcf_pic16
Testfile for CAN.
(7.5 KiB) Downloaded 269 times

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: dsPIC and internal CAN

Post by Mikat »

Hi.

I have used the internal CAN at 30F6012A, but I don't remember have I used it to send data or just receive at the moment...
I take quick look at your code, and only difference what I see the code that I use is that you use very slow speed, mine is 250Kb/s, and at the set tx data, you set that data field is only 1 byte long, but then you set 8 bytes of data, but I don't think thats the issue..
How about the hardware, do you use MCP2551 driver, or something else? The bus termination ok (120ohm resistor)?

beambase
Posts: 94
Joined: Wed Jul 29, 2009 5:15 pm
Has thanked: 6 times
Been thanked: 8 times
Contact:

Re: dsPIC and internal CAN

Post by beambase »

Hello
yes I am using the MCP2551 as the driver. I also have an opto isolation between the 30F6012A and the MCP2551.
When I measurethe CAN traffic I am using a can>usb analyzer on the output of the MCP2551 (with proper termination). The anlyser can be seen on http://www.canusb.com and has worked well before with can solutions using Flowcode and the 18F series of chips. I am also looking at the CAN RX and TX lines with a analyser at the logic level directly on the output of the 30F6012A. I am using a Scanlogic 2 that can be seen at http://www.ikalogic.com. This one also has proven to work well with Flowcode and 18F PICS.

I have tried various lenghts of the databacket but no success. The hardware is my own and it is a dense SMD design so it is not easy to add testpoints etc to it but I will try to get the breadboard version of the circuit together and see if that works better in some way.
Attachments
image2993.png
PCB
(255.85 KiB) Downloaded 4745 times

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: dsPIC and internal CAN

Post by Mikat »

Hi.

You are using CAN1? The can hi and can lo connected right (it isn't one or two times when I have mixed the can hi and lo :oops: ..)?
I'll try test the can transmit at dspic when I have some time, but it might go at next week... Have you use that optoisolation before at 18F?


Mika

beambase
Posts: 94
Joined: Wed Jul 29, 2009 5:15 pm
Has thanked: 6 times
Been thanked: 8 times
Contact:

Re: dsPIC and internal CAN

Post by beambase »

Ok,
I found something interesting...
The macros SetTxID and SetTxData seams to be writing the CAN controller registers in a faulty way. If i set the TxID and TxData in the CAN component settings and they are written when CAN is initilized at the start of the program,I get transmissions without errors. Also a workaround is to SetTxId, msend the message in the buffer and then do the SetTxData it seams to work. Not totally errorfree but most messages are sent ok. Attached is an example so you can understand what I mean.

Is there a modified CAN component that fixes this?
Attachments
6012ACantest1.fcf_pic16
CAN test
(9 KiB) Downloaded 274 times

beambase
Posts: 94
Joined: Wed Jul 29, 2009 5:15 pm
Has thanked: 6 times
Been thanked: 8 times
Contact:

Re: dsPIC and internal CAN

Post by beambase »

Mikat wrote:Hi.

You are using CAN1? The can hi and can lo connected right (it isn't one or two times when I have mixed the can hi and lo :oops: ..)?
I'll try test the can transmit at dspic when I have some time, but it might go at next week... Have you use that optoisolation before at 18F?


Mika
Hello
yes, I am using CAN1 and I have got the Tx and Rx pins right. And the optoisolation circuit is tested on a bredboard etc. I've checked the signal on a scope and the transmission is fine with very straight edges etc. It seams to be a problem with the SetTxID and SetTxData and how they write to the CAN controller register. Maybe it is the issue as with the EEPROM component writing to the wrong registers on the 30F6012A. It seams that the dsPIC is not a very mature and tested product in some ways.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: dsPIC and internal CAN

Post by Benj »

Hello,

Sorry to hear about the problems your having with the internal CAN on the dsPIC30 device. I will have a look into this. We are currently using the internal CAN here to control the new range of MIAC Add-on devices so it's working fine here. Attached is the latest version of the v4 CAN component for you to try.
PIC16BIT_CAN.c
(53.66 KiB) Downloaded 304 times
Let me know how you get on with it.

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: dsPIC and internal CAN

Post by Mikat »

Ben, does that component fix the problem with rx filters and mask WITH 30F6012A? Because those was broken too, as I say out at some other topic...

Mika

beambase
Posts: 94
Joined: Wed Jul 29, 2009 5:15 pm
Has thanked: 6 times
Been thanked: 8 times
Contact:

Re: dsPIC and internal CAN

Post by beambase »

It seams as if there is a problem to place both the SetTxID and SetTcData macros in the same loop. They both work induvidualy if there is a Send macro between them or if theu are in separate loops. It is a bit unpractical but at least there is some kind of workaround for the problem. Do you have any idea what can be causing this problem?

beambase
Posts: 94
Joined: Wed Jul 29, 2009 5:15 pm
Has thanked: 6 times
Been thanked: 8 times
Contact:

Re: dsPIC and internal CAN

Post by beambase »

Hello,
in order to be able to change the Can address i had to use the following C code together with the 30F6012A chip. The macro SetTX Address does not work at all.

Code: Select all

// Request config mode.
	    C1CTRL = REQOP_CONFIG;

		// Wait till desired mode is set.
	    while( (C1CTRL & CAN_OP_MODE_BITS) != 0x80 );


		

		C1TX0CON = TXB0CTRL_VAL;	// Transmit Buffer 0 Control
		C1TX0SID = ((FCV_A2 << 5) | (FCV_A1 >> 3)) & 0x00FF;	//Transmit Preload S-ID

		

	    // Request normal mode.
	    C1CTRL = REQOP_NORMAL;

		// Wait till desired mode is set.
	    while( (C1CTRL & CAN_OP_MODE_BITS) != 0x00 );
FCV_A1 and FCV_A2 are variables used to set the TxHigh and TXLow addresses within flowcode.

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: dsPIC and internal CAN

Post by Mikat »

Hi.

Neither does set rx mask or filter...
By the way guys, where is the port C low input and output at the 30F6012A chip? There is only portC H option...


Mika

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: dsPIC and internal CAN

Post by Benj »

Hello,

Here is an updated FCD to fix the missing pins on PortC L.
Attachments
30F6012A.fcd
(14.89 KiB) Downloaded 210 times

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: dsPIC and internal CAN

Post by Mikat »

Ben.
There was some thing wrong about the file, I don't remember what, but I need to change something before the port was ok...
And other thing is that the internal can don't work at 100MHz chip clock, probably the fcan is too high..

Mika

Post Reply