|
|
View previous topic :: View next topic |
Author |
Message |
newguy
Joined: 24 Jun 2004 Posts: 1912
|
|
Posted: Mon Feb 13, 2017 5:30 pm |
|
|
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
|
|
Posted: Tue Feb 14, 2017 2:40 am |
|
|
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
|
|
Posted: Tue Feb 14, 2017 1:49 pm |
|
|
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. |
|
|
|
|
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
|