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

Interrupt_Variable_pass

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



Joined: 17 Oct 2011
Posts: 23
Location: Iran-tehran

View user's profile Send private message Send e-mail

Interrupt_Variable_pass
PostPosted: Wed Sep 18, 2013 10:55 am     Reply with quote

Hi all
is there any way for passing variables to the Interrupt functions ?
I have to use public vars for this purpose , but this way my program has became so complicated . and also variables witch are changed just one time in the beginning of the program should stand on ram for always.
tnx
_________________
thanks and hope of success for you
Mohammad_Hosein
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Wed Sep 18, 2013 11:00 am     Reply with quote

No.

Any variable is going to 'stand on RAM', even one that was passed (you would need to store it in the interrupt function, and since these can occur anywhere all variables used in interrupt functions use separate RAM).

You could generate a global pointer, that points to configuration data, which is then copied to local variables in the interrupt function, but it won't save any RAM, and will involve more complexity in the interrupt function, which should be avoided.

It rather sounds as if you are doing more in interrupts than should really be done in these.
mhjccsinfo



Joined: 17 Oct 2011
Posts: 23
Location: Iran-tehran

View user's profile Send private message Send e-mail

PostPosted: Wed Sep 18, 2013 11:16 am     Reply with quote

Ttelmah wrote:
No.

Any variable is going to 'stand on RAM', even one that was passed (you would need to store it in the interrupt function, and since these can occur anywhere all variables used in interrupt functions use separate RAM).

You could generate a global pointer, that points to configuration data, which is then copied to local variables in the interrupt function, but it won't save any RAM, and will involve more complexity in the interrupt function, which should be avoided.

It rather sounds as if you are doing more in interrupts than should really be done in these.

thanks
how fast!!!!!
Shocked Smile
thanks
_________________
thanks and hope of success for you
Mohammad_Hosein
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Sep 18, 2013 9:31 pm     Reply with quote

Quote:

changed just one time


do you mean:

* calculated and stored in a var?
* read digitally, or from an ADC and stored in var?
* read of eeprom ?
* some form of invariant constant value , known at compile time?
*other

some combination of the above?

Question
mhjccsinfo



Joined: 17 Oct 2011
Posts: 23
Location: Iran-tehran

View user's profile Send private message Send e-mail

PostPosted: Thu Sep 19, 2013 12:13 am     Reply with quote

I am Producing a software PWM that get's the freq and duty from operator and produce the desired pulse.

so I calculate about 8 variable ( all long ) and pass it to the ISR.
so they calculate one time and then they are just some consts.

I am writing it to use it as a library for all of my projects and deliver it to other for using it , but it's not good that a library contains a lot of public/global vars. Confused Sad
_________________
thanks and hope of success for you
Mohammad_Hosein
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Sep 19, 2013 9:33 am     Reply with quote

if there is no dependency on the value of these constant vars that MUST be computed in runtime-then by all means declare them CONSTS.

and when it comes to VARS operated on by the ISR or the main program,

if they are 8bits - you can just read them , any old time

if they are int16's or greater you can use this code to get an accurate read, with out disabling ints..

example code follows of how to do this

Code:

//count is the var shared by your ISR and main or other functions
// getcount returns the safe value of count
//.....two reads verify that it has not changed mid reading

signed int16 getcount(void){
    signed int16 local
    while (local!=count){local=count);
    return(local);}
mhjccsinfo



Joined: 17 Oct 2011
Posts: 23
Location: Iran-tehran

View user's profile Send private message Send e-mail

PostPosted: Fri Sep 20, 2013 2:08 am     Reply with quote

Quote:
if there is no dependency on the value of these constant vars that MUST be computed in runtime-then by all means declare them CONSTS.

I don't think if there can be any tool for this job.
Quote:

Code:

signed int16 getcount(void){
    signed int16 local
    while (local!=count){local=count);
    return(local);}


in your program: where does "count" variable come from?
_________________
thanks and hope of success for you
Mohammad_Hosein
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Fri Sep 20, 2013 3:00 am     Reply with quote

He is just showing you how to read a 16bit variable that updates asynchronously to the read (in the example called 'count'), but can be anything you want. This is a way of reading a variable which is updated in an interrupt and needs to be read outside, without having to disable interrupts to do it.

The point is that you test to see if the local value matches the variable. If it doesn't, you read the variable, and repeat. If the variable updates during either the read, or the test, it won't match, so the read will repeat.

This type of double read and test, is what is triggered by the keyword 'volatile', in C's that support this. However CCS, though claiming in the manual that the keyword "Tells the compiler optimizer that this variable can be changed at any point during execution.", doesn't actually do anything about it....
It was one of the things I had hoped V5 would fix.

Best Wishes
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