www.micro-examples.com
Microcontroller circuits and source code examples
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 

question on "Multiple non-blocking delays with 1 timer&

 
Post new topic   Reply to topic    www.micro-examples.com Forum Index -> Discussion About the Examples
View previous topic :: View next topic  
Author Message
storic



Joined: 04 Aug 2007
Posts: 3
Location: SA Australia

PostPosted: Sun Aug 05, 2007 12:40 am    Post subject: question on "Multiple non-blocking delays with 1 timer& Reply with quote

thank you for sharing this code, it was something I was going to do, started several times with similar code however was not sure about how to go about it until now.

with regards to the struct
Code:
void            (*stop)() ;     // pointer to a function to call after delay

Is this call to a dummy function so you know when you are at the end or is there an actual function called stop within "MikroE C"

I take it
Code:
KEY_STRUCT      keys[NBKEYS] ;          // struct array
refers to the number of STRUCT's with the keys[NBKEYS] =2

Code:
void    keyStart(unsigned char i, unsigned long d)

you have made it in ms. I would be making it in sec as I would be looking for up to several minuets/hours in some instants.

with this code. am I to understand that I can delay an output until on or off by a set count and while during this process, I can set another delay function without effecting the first delay function thus creating 2 (keys[NBKEYS] ) independent delays. More if NBKEYS is more than 2.

One addition is I would add with #define NBKEYS 2
Code:

#define CPU 0
#define TimeON 1
//etc to be able to ID
// keyStart(0, 2000) ;   to read   keyStart(CPU, 2000) ;  // #0 = CPU


Andrew Confused
Back to top
View user's profile Send private message
BrunoG
Site Admin


Joined: 22 Nov 2005
Posts: 636

PostPosted: Sun Aug 05, 2007 10:18 pm    Post subject: Re: question on "Multiple non-blocking delays with 1 ti Reply with quote

Hi Andrew, nice to see you here Wink

storic wrote:
thank you for sharing this code, it was something I was going to do, started several times with similar code however was not sure about how to go about it until now.

with regards to the struct
Code:
void            (*stop)() ;     // pointer to a function to call after delay

Is this call to a dummy function so you know when you are at the end or is there an actual function called stop within "MikroE C"

stop is a member of a structure : it is a pointer to a function with no parameters and no return value.
this pointer must be assigned to a valid user's function, that will be called when the corresponding delay has expired.

Quote:
I take it
Code:
KEY_STRUCT      keys[NBKEYS] ;          // struct array
refers to the number of STRUCT's with the keys[NBKEYS] =2

keys is an array of NBKEYS (i.e 2) elements of KEY_STRUCT type structure.

Quote:

Code:
void    keyStart(unsigned char i, unsigned long d)

you have made it in ms. I would be making it in sec as I would be looking for up to several minuets/hours in some instants.

since the delay in ms is an unsigned long integer, you can have delays up to 49 days approximately Mr. Green

Quote:

with this code. am I to understand that I can delay an output until on or off by a set count and while during this process, I can set another delay function without effecting the first delay function thus creating 2 (keys[NBKEYS] ) independent delays. More if NBKEYS is more than 2.

That's it !

Quote:
One addition is I would add with #define NBKEYS 2
Code:

#define CPU 0
#define TimeON 1
//etc to be able to ID
// keyStart(0, 2000) ;   to read   keyStart(CPU, 2000) ;  // #0 = CPU


Andrew Confused


Yes, no problem !
_________________
BrunoG, Administrator
Back to top
View user's profile Send private message Send e-mail
storic



Joined: 04 Aug 2007
Posts: 3
Location: SA Australia

PostPosted: Tue Aug 07, 2007 11:00 am    Post subject: Re: question on "Multiple non-blocking delays with 1 Reply with quote

BrunoG wrote:
Hi Andrew, nice to see you here Wink

storic wrote:
thank you for sharing this code, it was something I was going to do, started several times with similar code however was not sure about how to go about it until now.

with regards to the struct
Code:
void            (*stop)() ;     // pointer to a function to call after delay

Is this call to a dummy function so you know when you are at the end or is there an actual function called stop within "MikroE C"

stop is a member of a structure : it is a pointer to a function with no parameters and no return value.
this pointer must be assigned to a valid user's function, that will be called when the corresponding delay has expired.


I am impress, I did not see it at first, it took some time to see how the function was part of the struct, I was looking at the code not the meaning of the code (looking at the forest untill I saw the tree) this line " keys[0].stop = toggleC ;" was when I understood it. Thanks Shocked

I have to say it would have taken me many moons to get to this stage, so my statement "with similar code" was not true. I should of said "with clunky, disjointed code" Embarassed

thanks again
_________________
What has been learnt if you make the same mistake? Wink
Back to top
View user's profile Send private message
BrunoG
Site Admin


Joined: 22 Nov 2005
Posts: 636

PostPosted: Tue Aug 07, 2007 9:54 pm    Post subject: Reply with quote

Hi Storic, you're welcome.
Have a great walk through the forest !
_________________
BrunoG, Administrator
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    www.micro-examples.com Forum Index -> Discussion About the Examples All times are GMT + 1 Hour
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