CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

18f4685 CAN

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Lemosek



Joined: 15 Oct 2011
Posts: 36

View user's profile Send private message

18f4685 CAN
PostPosted: Wed Feb 15, 2012 1:30 pm     Reply with quote

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: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Wed Feb 15, 2012 2:29 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 15, 2012 2:52 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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