View previous topic :: View next topic |
Author |
Message |
Lemosek
Joined: 15 Oct 2011 Posts: 36
|
18f4685 CAN |
Posted: Wed Feb 15, 2012 1:30 pm |
|
|
Hello,
I have one problem with CAN bus.
In my test program I use Timer2 to interrupt every 1ms.
Code: |
#int_timer2
void isr_timer2(void) {
ms++; //keep a running timer that increments every milli-second
if(ms>100)
{
ms=0;
pos_high=make8(position,1);
pos_low=make8(position,0);
buffer[0]=pos_high;
buffer[1]=pos_low;
buffer[2]=current_fault;
buffer[3]++;
buffer[4]++;
buffer[5]++;
buffer[6]++;
buffer[7]++;
can_putd(BOARD2_ID, buffer, 8, 1, 1, 0);
}
|
Every 100ms I put data to CAN bus. If in main function I don't have delay function, transmission is ok. But if I use delay, transmission is slower then.
Its look like it stop for few ms.
Best regards
R.L. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Wed Feb 15, 2012 2:29 pm |
|
|
You should never do this kind of thing in an interrupt. Set a flag when
100ms passes then check the flag in main to transmit the CAN data.
The rule is ALWAYS get out of an interrupt as quickly as possible. In this
case your 1ms timer is going to try to fire again before you get out of the
100ms servicing routine! The only alternative would be to disable
interrupts... _________________ Google and Forum Search are some of your best tools!!!! |
|
|
Lemosek
Joined: 15 Oct 2011 Posts: 36
|
|
Posted: Wed Feb 15, 2012 2:52 pm |
|
|
Hello,
I know this. This example is only for testing. I'm interesting why this happens.
I am always thinking, when interrupt is set then main program is stop and after execute interrupt go back to main. So why bus is slower ?
Best regards
R.L. |
|
|
|