Flowcode and Internal CAN

Repository for articles written about Matrix Hardware and Software. Example code, Tips, Tricks and methods for programming.

Moderators: sean, Mods

Flowcode and Internal CAN

Postby steve on Thu May 13, 2010 9:32 am

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_advanced_course.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
CAN01.png (9.54 KiB) Viewed 564 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
CAN02.png (13.11 KiB) Viewed 564 times
Attachments
Internal_CAN_Files_AVR.zip
(39.36 KiB) Downloaded 31 times
Internal_CAN_Files_PIC.zip
(105.99 KiB) Downloaded 66 times
Steve Tandy,
Matrix Multimedia Ltd.
User avatar
steve
 
Posts: 1951
Joined: Tue Jan 03, 2006 3:59 pm
Location: Matrix Multimedia Ltd.

Re: Flowcode and Internal CAN

Postby MW on Tue May 18, 2010 6:11 am

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
MW
 
Posts: 25
Joined: Mon Feb 26, 2007 2:04 am

Re: Flowcode and Internal CAN

Postby Benj on Tue May 18, 2010 8:58 am

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.
Regards
Ben Rowland
Matrix Multimedia
User avatar
Benj
 
Posts: 3472
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd

Re: Flowcode and Internal CAN

Postby MW on Tue May 18, 2010 9:19 am

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
MW
 
Posts: 25
Joined: Mon Feb 26, 2007 2:04 am

Re: Flowcode and Internal CAN

Postby Markro on Mon Jun 14, 2010 4:58 pm

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
Markro
 
Posts: 16
Joined: Sun Sep 23, 2007 12:41 am

Re: Flowcode and Internal CAN

Postby sean on Tue Jun 15, 2010 3:24 pm

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.
User avatar
sean
 
Posts: 417
Joined: Tue Jun 26, 2007 11:23 am

Re: Flowcode and Internal CAN

Postby MW on Fri Jun 18, 2010 7:32 am

Hi,

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

Cheers
MW
MW
 
Posts: 25
Joined: Mon Feb 26, 2007 2:04 am

Re: Flowcode and Internal CAN

Postby Benj on Fri Jun 18, 2010 10:55 am

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?
Regards
Ben Rowland
Matrix Multimedia
User avatar
Benj
 
Posts: 3472
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd

Re: Flowcode and Internal CAN

Postby MW on Fri Jun 18, 2010 10:59 am

No problem at all. Thanks very much
MW
 
Posts: 25
Joined: Mon Feb 26, 2007 2:04 am

Re: Flowcode and Internal CAN

Postby cantronicx on Wed Jul 28, 2010 9:20 pm

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.
cantronicx
 
Posts: 8
Joined: Fri Jul 23, 2010 9:53 pm

Re: Flowcode and Internal CAN

Postby Benj on Thu Jul 29, 2010 8:28 am

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 12 times
Regards
Ben Rowland
Matrix Multimedia
User avatar
Benj
 
Posts: 3472
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd

Re: Flowcode and Internal CAN

Postby cantronicx on Thu Jul 29, 2010 5:06 pm

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

Any more ideas or sugestions... anyone?? Please
cantronicx
 
Posts: 8
Joined: Fri Jul 23, 2010 9:53 pm

Re: Flowcode and Internal CAN

Postby Benj on Mon Aug 09, 2010 8:27 am

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.
Regards
Ben Rowland
Matrix Multimedia
User avatar
Benj
 
Posts: 3472
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd

Re: Flowcode and Internal CAN

Postby cantronicx on Mon Aug 09, 2010 3:08 pm

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?
cantronicx
 
Posts: 8
Joined: Fri Jul 23, 2010 9:53 pm

Re: Flowcode and Internal CAN

Postby Benj on Tue Aug 10, 2010 8:53 am

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.74 KiB) Downloaded 3 times
Regards
Ben Rowland
Matrix Multimedia
User avatar
Benj
 
Posts: 3472
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd

Re: Flowcode and Internal CAN

Postby cantronicx on Tue Aug 10, 2010 5:23 pm

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.
cantronicx
 
Posts: 8
Joined: Fri Jul 23, 2010 9:53 pm

Re: Flowcode and Internal CAN

Postby Benj on Wed Aug 11, 2010 8:36 am

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.73 KiB) Downloaded 3 times
Regards
Ben Rowland
Matrix Multimedia
User avatar
Benj
 
Posts: 3472
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd


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
3
100%
 
Total votes : 3

Return to Articles

Who is online

Users browsing this forum: keshav@solus.in and 1 guest