CAN 1Mbits/s Transmission Period?

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am trying to transmit data through CAN bus, baud rate 1M bits/s. 

 

I am using ATmega32C1 and 8Mhz crystal. 

 

I calculated the transmission time for 1Mbits/s CAN bus to send a CAN msg, it was 128bit/(1*10^6) = 128 us. 

 

When I scoped the bus, the time difference of start of msg and end of msg was about 150 us, which made sense to me. 

but when I checked the time between messages, one afther another, there is huge gap between msgs, about 200us. 

So, the time difference between the first msg sending point and the second msg sending point is about 360 us. 

 

Is there some sort of overhead? Is there any delay between messages? 

 

Here is my setting.

 

 


// this is timer part
#define TIMER0_OUTPUT_COMPARE		40
void	TMR_Init(void)
{

/*	Initialize Timer 0*/
	TCCR0A = (1<<WGM01); //setting second bit 1 (TCCR0 = timer/counter control register)
	TCCR0B = TIMER0_PRESCALE_DIV_64;//TIMER0_PRESCALE_DIV_64; /* WGM01: Clear on compare match*/ 
	OCR0A = TIMER0_OUTPUT_COMPARE; //40 OCR0 = output compare register
	TIMSK0 |= (1<<OCIE0A);
/* 	Initialize Timer 1*/
//
	TCCR1A = (1<<WGM10) | 
			(1<<COM1A0) | 
			(1<<COM1A1) | 
			(0<<COM1B0) | 
			(1<<COM1B1);  /*8 bit PWM*/
	TCCR1B = TIMER1_PRESCALE_DIV_1;
}

//Interrupt for timer0 when CTC
ISR(TIMER0_COMPA_vect)
{	
	unsigned char j = 0;

	for (j = 0; j < byTmrIdx; j++)
	{
		if (wTimerArray[j] != 0) {wTimerArray[j]--;}
	}
}


// this is CAN_AVR part
#elif (F_CPU == 8000000UL)
	#define CAN_BT1	0x00 //0x00 for 1M/bits
	#define CAN_BT2	0x04 //0x0C 0x04 0x04
	#define CAN_BT3	0x12 //0x37 0x13 0x12

 

AVR

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your code does not show what is happening between messages, ie. main()  What do you do to generate messages(processing), are messages to be transmitted buffered? 

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

msg.ID = J1939_lHeaderToID(byBtnPri, wBtnPGN, J1939_byGetSA());

msg.DLC = BUTTON_LEN;

J1939_vSendMsg((pj1939msg)&msg);

 

I am using CAN_AVR.c library to send a CAN msg. 

This J1939_vSendMsg is calling  CAN_bySendMsg(pcanmsg cm) inside CAN_AVR.c. 

 

I don't think this is buffered. The reason why i am doing this is to get rid of any overhead that might cause delay between msgs. 

 

The code I uploaded is just snippet of each setting. It is not contigous. 

 

 

Every time IRS is called it decrements the counter. When this counter hits the zero, it allows to send message using funcitons I noted here. 

AVR

Last Edited: Fri. Nov 3, 2017 - 04:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Heijey wrote:
Every time IRS is called it decrements the counter. When this counter hits the zero, it allows to send message using funcitons I noted here.

 

Then is that not the source of the delay if it has to wait for the ISR(IRS?) to trigger the next CAN msg send???????

 

 

Jim

To go any further: please post a small, complete, program that demos the problem (often the answer will revel itself when doing this) that a freak can compile and test.

the shown snippets are useless in providing the answers you seek.

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My bad. I wasn't familar with posting Discussion in AVR freak. I will dig into it more and then will update the code again. 

It seems like there is some sort of mandatory interpacket gap in CAN bus

AVR

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@Heijey said:

I wasn't familar with posting ... will update the code again. 

Don't update the code in your original post, post the new/updated code in a reply.

 

 

@Heijey said:

It seems like there is some sort of mandatory interpacket gap in CAN bus

And you are just discovering this?  You need to know how CAN works before to start implementing it.

 

BTW, the code you posted doesn't do a thing with the CAN registers:

 

Greg Muth

Portland, OR, US

Atmel Studio 7.0 on Windows 10

Xplained/Pro/Mini Boards mostly

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

 

https://www.google.com/url?sa=t&...

 

 

Edit: 3rd times a charm

Last Edited: Fri. Nov 3, 2017 - 07:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you. I will dig into it little more before I actually implement it.

AVR

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To the OP -

 

CAN is not just "another serial bus". It has a highly defined protocol that is usually managed inside the CAN controller as a "stack". In this regard, it is much more like tcp/ip than like generic async serial. 

 

The point of this is that you cannot use it blindly. There are many parameters that need to be configured. 

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net