|
|
View previous topic :: View next topic |
Author |
Message |
Uncle Fungus
Joined: 21 Aug 2012 Posts: 1 Location: Silverstone UK
|
Strange CAN ID Behaviour on multiple ID's |
Posted: Wed Mar 20, 2013 4:34 am |
|
|
Compiler PCH 4.121
PIC 18F26K80 and 4580
I am having a strange issue when transmitting 2 messages on to the CAN bus (each with a different ID).
"Most" of the time the data transmits fine, approximately every 26th transmission though, there is a "BLIP" in the transmitted data - but not allways!!
The Code is designed to transmit 2 CAN messages. Each message is transmitted every 2mS, with 1mS between different ID's. This is the Spec, and I can't change it because of the software the other end receiving the message.
Thinking there was a bug in my compiler, I even wrote in Assembler, but with the same result, making me think there is some sort of hardware issue with the device. I then compiled the code to run on a PIC18F4580, with the same result, so it must be me??!!
If I don't alternate the CAN ID, between messages all is well, but I need 2 ID's to get the data out.
To simplify the code I created a 16-bit value which increments by 60 every CAN transmission - It should be a straight line, but, it isn't. If the value is a constant, then there are no Blips allmost as if the CAN transceiver is shifting the data out incorrectly - but why only when I use 2 ID's??!!
Code: |
//Loop indefinately
while(TRUE)
{
// while(125>Get_Timer0());//wait for 1mS 64MHz CLK /128 TMRO0
while(78>Get_Timer0());//wait for 1mS
Set_Timer0(0);
//Get some data ready to pass to the CAN function
ADCVal[0]=ADCVal[0]+60;
ADCData[1]=make8(ADCVal[0],1);
ADCData[0]=make8(ADCVal[0],0);
//decide which 4 channels to transmit
if(TX1_4==0)
{
TransmitCAN1(tx_id,ADCData);
TX1_4=1;//change for next time
}
else
{
TransmitCAN1(tx_id+1,ADCData);
TX1_4=0;//change for next time;
}
}
//
}
|
AND
Code: |
//Transmit the Data of the required channel
void TransmitCAN1(unsigned int32 ID,unsigned int8 CANArray[8])
{
int i;
out_data[0]=CANArray[1];
out_data[1]=CANArray[0];
//
out_data[2]=0;
out_data[3]=0;
//
out_data[4]=0;
out_data[5]=0;
//
out_data[6]=0;
out_data[7]=0;
//Transmit the CAN Data
//ensure txbuffer is empty
if(can_tbe())
{
can_putd(ID, out_data, tx_len,tx_pri,tx_ext,tx_rtr); //put data on transmit buffer
}
} |
|
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Thu Mar 21, 2013 1:59 am |
|
|
Define "BLIP". Is it missing data or corrupted data? If corrupted, what sort of values are being received? Data corruption should be rejected by the receiver due to CRC mismatch. Can you set up a second receiver on the bus to output all packets? _________________ Andrew |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Thu Mar 21, 2013 3:15 pm |
|
|
You would not, by chance, be getting hit with an interrupt in the middle of sending the message would you ? Especially with any kind of software uart, interrupts can cause very strange things if they happen when you don't expect them (which is usually when they happen right?)
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|