Flowcode and Internal CAN

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Please rate this article out of 5: (1 being the worst and 5 being the best)

1
0
No votes
2
0
No votes
3
0
No votes
4
0
No votes
5
6
100%
 
Total votes: 6

User avatar
Steve
Matrix Staff
Posts: 3418
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Flowcode and Internal CAN

Post by Steve »

CAN stands for Controller Area Network and is a popular bus which is heavily used in today’s automotive environment for communicating between microcontroller nodes where each node is responsible for completing or monitoring a specific task. CAN bus is also suitable for applications other than just automotive due to its low cost, message-based protocol, high immunity to noise and maximum transmission distance between nodes.

Some of the newer PICmicro and AVR microcontrollers have been fitted with internal CAN modules, which allow for the device to connect up to the bus using minimal external circuitry. The advantages of using the internal modules over using an external CAN chip are that there is less circuit complexity and cost due to the reduced parts count, plus faster transmissions due to direct register read/write access.

A full manual detailing our CAN solution and Flowcode’s CAN component can be found here:
http://www.matrixmultimedia.com/lc_adva ... .php#EB744

There is also a good help file available for use with the Flowcode component by selecting the component in Flowcode and then clicking the help button on the sidebar.

The internal CAN functionality is loaded into Flowcode based on which target family you are using.


PICmicro

For PICmicro devices with internal CAN you can modify the CAN component by updating the C code and the OCX files that drive the operation of the CAN component. These files can be found in the “Flowcode V4/Components” directory. Once you have done this the properties, hardware macros will all work seamlessly with the internal CAN registers. A clock speed of 20MHz is recommended for the default baud settings but if you require an alternative clock speed then you simply have to use the calculator included in the component properties to work out a feasible baud rate.

Here are some examples of working baud rates at different crystal speeds.

125KHz @ 8MHz – BRGCON1=0x3 BRGCON2=0xC9 BRGCON3=0x02
125KHz @ 16MHz – BRGCON1=0x7 BRGCON2=0xC9 BRGCON3=0x02
125KHz @ 24MHz – BRGCON1=0xB BRGCON2=0xC9 BRGCON3=0x02
125KHz @ 40MHz – BRGCON1=0xF BRGCON2=0xD1 BRGCON3=0x03

250KHz @ 8MHz – BRGCON1=0x1 BRGCON2=0xC9 BRGCON3=0x02
250KHz @ 16MHz – BRGCON1=0x3 BRGCON2=0xC9 BRGCON3=0x02
250KHz @ 24MHz – BRGCON1=0x5 BRGCON2=0xC9 BRGCON3=0x02
250KHz @ 40MHz – BRGCON1=0x7 BRGCON2=0xD1 BRGCON3=0x03

Supported PICmicro devices with internal CAN functionality include: 18F2480, 18F2580, 18F2585, 18F2680, 18F2682, 18F2685, 18F4480, 18F4580, 18F4585, 18F4680, 18F4682 and 18F4685.
CAN01.png
(9.54 KiB) Downloaded 23229 times
AVR

For AVR devices with internal CAN you again must modify the component by replacing the C code that drives the component. With the AVR devices the internal CAN organisation is not the same as the standard Microchip external CAN chip so the properties of the CAN component do not match. This means that any settings from the Flowcode CAN component properties will be lost so therefore the functionality needs to be brought out into your Flowcode program. If you are relying on these properties in an existing program then you will have to edit your program or use the existing method of using the Microchip external CAN driver. Alternatively you can use one of the PIC devices mentioned above.

The AVR internal CAN driver only supports a bus speed of 125KHz and only supports the following crystal frequencies: 4MHz, 6MHz, 8MHz, 12MHz, 16MHz, 18MHz and 20MHz. Any other clock speed setting in the project options window will result in a compilation error without manually editing the C code behind the CAN component.

Supported Atmel AVR devices with internal CAN functionality include: AT90CAN32, AT90CAN64 and AT90CAN128.

Please note that the modification for the internal CAN module of AVR devices is provided as-is and we can offer very limited support for it at the present time.


CAN Driver Chip

The CAN bus operates using a differential signal to allow for the high noise immunity. The I/O pins of the microcontroller cannot directly produce a differential signal so an external driver chips is still required for the CAN to work correctly. This is however much less then the cost of the external CAN controller chip.

Here is a basic circuit to allow you to use the internal CAN with an external CAN driver chip to produce a fully operational system.
CAN02.png
(13.11 KiB) Downloaded 23229 times
Attachments
Internal_CAN_Files_AVR.zip
(39.36 KiB) Downloaded 904 times
Internal_CAN_Files_PIC.zip
(105.99 KiB) Downloaded 1181 times

MW
Posts: 38
Joined: Mon Feb 26, 2007 2:04 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Flowcode and Internal CAN

Post by MW »

Steve,

This is a great development and something I have an immediate use for.

Is there a way to use to use the internal CAN modules to transmit 29 bit message ID's?

Thanks
MW

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: Flowcode and Internal CAN

Post by Benj »

Hello,

The internal CAN driver currently only supports standard identifiers. It would not be much work to modify the component further to allow for extended identifiers if these are a requirement for you.

MW
Posts: 38
Joined: Mon Feb 26, 2007 2:04 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Flowcode and Internal CAN

Post by MW »

Hi Ben,

I primarily require extended identifiers, so if it is possible to update the component to include these it would be a massive help.

Regards
MW

Markro
Posts: 20
Joined: Sun Sep 23, 2007 12:41 am
Contact:

Re: Flowcode and Internal CAN

Post by Markro »

Hello,

Is it possible to set the buad rate to 100 kbps using the flowcode components for MIAC ?

I have looked at the component and all the popular baud rate are there, but I know there are some systems using 100kbps rates.

Thanks

Mark

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: Flowcode and Internal CAN

Post by Sean »

Hello,

It is possible to set bit rates that are not directly supported by the Flowcode component. To do this it is necessary to enter register values for CNF1, CNF2, CNF3, directly after selecting the 'Override register values' option.

Microchip's application note AN754 provides a detailed explaination of the function of these registers. The Fosc value for the MIAC CAN controller is 20MHz.

MW
Posts: 38
Joined: Mon Feb 26, 2007 2:04 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Flowcode and Internal CAN

Post by MW »

Hi,

Has any further thought been given to if or when extended identifiers will be included in the component?

Cheers
MW

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: Flowcode and Internal CAN

Post by Benj »

Hello,

Yes I will get around to doing this eventually. However im currently looking into FAT32 possibility (which to be honest is now mostly working). I have some CAN bus PCB's on route to me next week so I will probably take this oppertunity to add the extended ID functionality. Is waiting another week going to be ok?

MW
Posts: 38
Joined: Mon Feb 26, 2007 2:04 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Flowcode and Internal CAN

Post by MW »

No problem at all. Thanks very much

cantronicx
Posts: 16
Joined: Fri Jul 23, 2010 9:53 pm
Has thanked: 4 times
Been thanked: 1 time
Contact:

Re: Flowcode and Internal CAN

Post by cantronicx »

Looks good but after downloading the file and installing them, I get a message
" Unable to create microcontroller AT90CAN128 as the definition file
AT90CAN128.FCD is missing or corrupt. [0x1e00]"

By restoring only the three FCD files (AT90CAN128,AT90CAN64,AT90CAN32), Flowcode V4 (version 4.3.6.61) will then work but there is no internal CAN-BUS option. Guessing in that part is in the FCD file and its support files located elsewhere are not the problem in that those are still installed.

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: Flowcode and Internal CAN

Post by Benj »

Hello,

Here is a copy of the AVR archive that includes v4 AVR FCD files as well as the v3 ones.

The internal CAN component is selected by renaming the CAN_Code_Internal.c file to the CAN_Code.c file.
Attachments
Internal_CAN_Files_AVR.zip
(48.43 KiB) Downloaded 676 times

cantronicx
Posts: 16
Joined: Fri Jul 23, 2010 9:53 pm
Has thanked: 4 times
Been thanked: 1 time
Contact:

Re: Flowcode and Internal CAN

Post by cantronicx »

downloaded the file and followed your instruction... the results are the same and no internal can-bus.

Any more ideas or sugestions... anyone?? Please

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: Flowcode and Internal CAN

Post by Benj »

Hello,

Does the new FCD file from the archive now work correctly?

Also what are you communicating with? Have you checked that the baud rate is compatible. the baud rate is set in the defines section and you should be able to refer to the device datasheet to get the correct baud settings to match your device. The current baud rate is 125Kbps.

Have you connected up the driver chip as shown in the schematic above?

I know the AVR CAN code works if all the conditions are met as it is currently running on a large number of motor home and caravan control units.

You may also want to ensure that your device is running at the right rate of 20MHz. If the configuration is not correct then the device will run at a speed of divide by 8. A quick 1 second flasher test program should proove if your configuration is correct.

Let me know how your getting on.

cantronicx
Posts: 16
Joined: Fri Jul 23, 2010 9:53 pm
Has thanked: 4 times
Been thanked: 1 time
Contact:

Re: Flowcode and Internal CAN

Post by cantronicx »

The error I get is when I select the patched FCD file is --
"unable to create microcontroller AT90CANxxx as the definition file AT90CANxxx.FCD is missing or corrupted. [0x1e00]"

If I just replace all the other files as well as doing the renaming part but leave the AT90CANxxx.fcd files untouched, Flowcode will not complain.

The files CAN-Code.c and CAN_Code_internal.c are identical, with only one exception "FCD_Custom0_can_init();" at line 306. Is that the only difference?

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: Flowcode and Internal CAN

Post by Benj »

Hello,

This AVR FCD is working fine for me in v4 of Flowcode AVR.

The CAN_Code.c file is the working file. There are two other files that can be switched in by remaning them to "CAN_Code.c"

These files are.....

CAN_Code_Eblock.c - Standard External CAN
CAN_Code_Internal.c - Modified Internal CAN

Are you using a clock speed of 20MHz?
Is the baud rate of the other CAN device correct?
Attachments
AT90CAN128.fcd
(11.28 KiB) Downloaded 585 times

cantronicx
Posts: 16
Joined: Fri Jul 23, 2010 9:53 pm
Has thanked: 4 times
Been thanked: 1 time
Contact:

Re: Flowcode and Internal CAN

Post by cantronicx »

I am using the AT90CAN32 running at 16Mhz at the moment. The other circuit that I am using is the EB019 connected to a CAN Bus controller as in the EB018 running at 20Mhz of which the EB019 ucontroller is the ATmega324P running at 20Mhz (or so it says 20Mhz). The idea is to program the AT90CAN32/64/128 and communicate to the other circuit, EB019 and EB018.
the problem is the files are returning an error (see above) when flowcode starts with those atcanxxx.fcd and can not even start to program.

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: Flowcode and Internal CAN

Post by Benj »

Hello,

Ok here is the v4 FCD for the AT90CAN32 device.

You will need to run the device at 20MHz and with the driver chip fitted and then it should communicate correctly with the EB018 E-block.
Attachments
AT90CAN32.fcd
(11.28 KiB) Downloaded 575 times

cantronicx
Posts: 16
Joined: Fri Jul 23, 2010 9:53 pm
Has thanked: 4 times
Been thanked: 1 time
Contact:

Re: Flowcode and Internal CAN

Post by cantronicx »

Why would I want any communications to an external CAN controller when the point of this subject is to use the INTERNAL CAN bus controller?
Please reply with a fix that is based on the subject at hand and not deviate from this point of view.

Darkstar
Posts: 4
Joined: Wed Feb 02, 2011 6:59 pm
Contact:

Re: Flowcode and Internal CAN

Post by Darkstar »

I am getting ready to purchase v4 (PIC) and FlowKit (good combo price btw) and will defiantly need the extended internal can functions.... did this ever get completed?

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: Flowcode and Internal CAN

Post by Benj »

Hello Darkstar,

Flowcode PIC definatley works at the moment with internal CAN. If you need extended IDs then this may not be currently supported I can't remember where we got with this. Anyway if you need it and its not working then let us know on the forums and we will get it sorted for you. Shouldn't be much of a job as most of the work is in moving from external to internal functionality which has already been done.


Hello Cantronix,

Sorry for the delay here, I saw you mentioned the EB018 and just assumed from there. Sorry about that must have been having a long day. Anyway can you compile any code to a AT90xxxCAN device? I have got this working fine as I do a lot of development with these devices. Let me know hw your getting on and if you still need me to look into this for you.

Darkstar
Posts: 4
Joined: Wed Feb 02, 2011 6:59 pm
Contact:

Re: Flowcode and Internal CAN

Post by Darkstar »

It's not something I can test as the demo doesn't allow for that. But the extended ID is critical to the project I am designing. I'll keep an eye out here and wait till it's implemented before I purchase.

Thank You,
Richard

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: Flowcode and Internal CAN

Post by Benj »

Hi Richard,

I've looked at the code and it should be a 5 minute job. Ill try and get it done next time I have 5 mins to spare :mrgreen:

Darkstar
Posts: 4
Joined: Wed Feb 02, 2011 6:59 pm
Contact:

Re: Flowcode and Internal CAN

Post by Darkstar »

Thanx!

Darkstar
Posts: 4
Joined: Wed Feb 02, 2011 6:59 pm
Contact:

Re: Flowcode and Internal CAN

Post by Darkstar »

Any updates?

Richard

MW
Posts: 38
Joined: Mon Feb 26, 2007 2:04 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Flowcode and Internal CAN

Post by MW »

This is still something I could really use

Post Reply