View previous topic :: View next topic |
Author |
Message |
mdemuth
Joined: 16 Apr 2007 Posts: 71 Location: Stuttgart, Germany
|
CAN-Bus help needed to get started with PIC18F2580 [solved] |
Posted: Fri Sep 14, 2012 3:04 am |
|
|
Hello,
I am just going to start my first CAN project and need some help on basic questions:
A CAN-Message send every 100ms with 500kbps needs to be writen on RS232
- can the internal oscillator with 32MHz be used?
- what is the setup for
CAN_BRG_PRESCALAR
CAN_BRG_PHASE_SEGMENT_1
CAN_BRG_PHASE_SEGMENT_2
CAN_BRG_PROPAGATION_TIME
CAN_BRG_SYNCH_JUMP_WIDTH
Compiler Version used: 4.124
Thanks in advance!
Michael
Last edited by mdemuth on Wed Sep 19, 2012 3:09 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
![](templates/subSilver/images/spacer.gif) |
mdemuth
Joined: 16 Apr 2007 Posts: 71 Location: Stuttgart, Germany
|
|
Posted: Fri Sep 14, 2012 6:11 am |
|
|
I will use a 10Mhz crystal and have the PLL enabled to get 40MHz.
Thanks for now! |
|
![](templates/subSilver/images/spacer.gif) |
mglsoft
Joined: 18 Feb 2008 Posts: 48
|
|
Posted: Fri Sep 14, 2012 6:43 pm |
|
|
I'll try the CAN bus using the internal oscillator of a PIC18F26K80.
Using a 16 MHz oscillator and the PLL reaches 64 Mhz activated.
Of course I'll leave the option to the external crystal, but is very stable so far, I am transmitting via RS232 to 460,800 bps without errors.
The CAN bus will use the speed of 250 Kbps, so I do not have problems with the bus, I will submit to all possible evidence, because it is very important in my application (hundreds of pieces), not having the cost of xtal. _________________ MGLSOFT |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Fri Sep 14, 2012 7:21 pm |
|
|
Be sure to test your product under actual conditions ! Especially wide temperature ranges !! The real world is far different than 'in the lab'.
You may find out that spending an extra 50cents now for a real xtal to control precise timing is money very well spent BEFORE hundreds of your product come back with 'it don't work right' comments.
At the very least when you design the PCB allow for the xtal and caps to be added in the near future....been there and done that so I ALWAYS use xtals in every product.
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
mglsoft
Joined: 18 Feb 2008 Posts: 48
|
|
Posted: Fri Sep 14, 2012 8:32 pm |
|
|
Of course I leave the circuit for xtal and capacitors!
Only that can represent a great advantage not having to use it.
Evidence freezer, oven and tools will be used to test the performance of these circuits, no doubt.
Thanks for your comment. _________________ MGLSOFT |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19372
|
|
Posted: Sat Sep 15, 2012 1:56 am |
|
|
Microchip, are very confident that something better than the internal oscillator is _needed_. The data sheet says:
"As a rule of thumb, the bit timing requirements allow
ceramic resonators to be used in applications with
transmission rates of up to 125 Kbit/sec. For the full bus
speed range of the CAN protocol, a quartz oscillator is
required. Refer to ISO11898-1 for oscillator tolerance
requirements.".
So they say that a ceramic resonator is adequate for low speed operation (up to 125Kbps), but for operation over this, a crystal oscillator is _required_ (no optional)...
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
mdemuth
Joined: 16 Apr 2007 Posts: 71 Location: Stuttgart, Germany
|
|
Posted: Tue Sep 18, 2012 10:30 am |
|
|
So far so good, I got it running but only half way.
I am successful in sending data to the Microchip CAN Bus analyser :-)
But I am not able to get any reaction on a CAN message sent by the analyser :-(
My Code:
Code: |
#include <18f2580.h> //
#device ADC=10 //
#fuses HS,H4,NOWDT,NOPROTECT,BROWNOUT,MCLR, BORV46,PUT
#use delay(clock=40000000)
#use rs232(stream=COM1, baud=9600,PARITY=N, BITS=8, STOP=1, UART1,ERRORS) //
#define CAN_DO_DEBUG TRUE
// Schaltausgänge
#define Sound PIN_C2
int16 counter8=0;
#include <can-18xxx8.c>
#zero_ram
void main()
{
int8 buffer[8], rx_len;
struct rx_stat rxstat;
int32 rx_id=0x301;
can_init();
//set_tris_b(0x0001000);
putc(0x0C); // Formfeed
delay_ms(200);
printf("Start\n\r");
while (1)
{
delay_ms(100);
counter8++;
can_putd(0x300, &counter8, 1,1,1,0); //put data on transmit buffer
if ( can_kbhit() )
{
if(can_getd(rx_id, &buffer[0], rx_len, rxstat))
counter8 = 0;
printf("\n\rMessage received");
}
}
} // Ende main
|
Anybody any ideas? |
|
![](templates/subSilver/images/spacer.gif) |
mdemuth
Joined: 16 Apr 2007 Posts: 71 Location: Stuttgart, Germany
|
Got it! |
Posted: Wed Sep 19, 2012 3:14 am |
|
|
The problem was related to the Microchip CAN BUS Analyser tool -
Transmitting messages with extended ID is tricky:
0x300 does not work, but 0x300x works fine. |
|
![](templates/subSilver/images/spacer.gif) |
|