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 CCS Technical Support

stopping process in PIC18F4550
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
newguy



Joined: 24 Jun 2004
Posts: 1912

View user's profile Send private message

PostPosted: Mon Feb 13, 2017 5:30 pm     Reply with quote

fly28 wrote:
My code is not blocking, it's working perfectly; only if I try to stop him earlier via USB I can't until it finishes.


That's literally the textbook definition of blocking code.
Ttelmah



Joined: 11 Mar 2010
Posts: 19641

View user's profile Send private message

PostPosted: Tue Feb 14, 2017 2:40 am     Reply with quote

You don't need a lot of timers to have a lot of timers. The PC for example has some specialist hardware timers, but most 'timing' functions are based upon a single 'heartbeat' tick.

As Newguy says, your code _is_ blocking.
I think you labour under the misbelief that you can implement a hardware 'branch' to other code. Fundamentally you can't. You don't need major code, but inside the core of your system you need something like this:

Code:


   //first have your 'sampling code', being inside a single 'wrapper' function
   int8 sampling(whatever it needs)
   {
       //then at some point that is happening reasonably frequently
       if (usb_kbhit())
            return FALSE;

      //then the normal exit
      return TRUE;
   }

Then your main code need only check the return status of 'sampling' to know that there has been an abnormal exit.

Honestly also though 'why struggle' trying to fit the code inside a 18F4550. Later chips have better features, more RAM and more ROM.

Problem is that trying to use an interrupt to 'exit' a function, requires your code to tidy up _everything_. Stack, temporary variables, hardware settings etc. etc. Bulkier, and more likely to go wrong, than simply having the main function do a clean exit. There is no provision in the PIC hardware to do a branch controlled by an interrupt.

Your project doesn't actually sound that complex. You are making it complex, by not actually structuring your thinking.
fly28



Joined: 11 Feb 2017
Posts: 9

View user's profile Send private message

PostPosted: Tue Feb 14, 2017 1:49 pm     Reply with quote

The idea seems to work if I put in each loop
"for ...."
that lasts more than few seconds, these 2 instructions:
Code:

if (usb_kbhit (1))
   {
      break;
    }

These instructions require 10 cycles and with a "nop" introduce a delay of 1 us that counted against instruction type delay_us(x) . Measurements with a frequency meter confirm the estimate made after studying of disassembly listing.

Finally I wish to thank to Ttelmah, newguy and "PCM programmer" for their support (and patience).

If someone has the same problem as me, then I can come back with details.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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