When ever you use a global variable, you have to specify it as a
volatile to tell the compiler not to opitmize the variable out of the
equation when working with any ANSI C compiler.
Also by type casting the variable the same as the register you want to
use makes sure that the compiler is not going to do something funky
when optimization is performed no matter what level.
regards,
Charles
--- In lpc2000@yahoogroups.com, capiman@t... wrote:
> The "volatile" is the thing, which makes it worth trying out...
>
> Regards,
>
> Martin
>
> ----- Original Message -----
> From: "ed_hage" <ed_hage@y...>
> To: <lpc2000@yahoogroups.com>
> Sent: Saturday, April 09, 2005 1:24 PM
> Subject: [lpc2000] Re: float in interrupt function?
>
>
> >
> >
> > I don't want to define DC1 = 20 inside the IRQfunction. That works
> > already. I want to use the value of DC1 = 90 instead that is defined a
> > a global,
> >
> > Already changed int to unsigned long because I also have defined some
> > other variables that way which I can manipulate with another
> > IRQfunction. But the results are the same.
> >
> > --- In lpc2000@yahoogroups.com, "charlesgrenz"
<charles.grenz@s...> wrote:
> >>
> >> Hi guys, just a thought, try this instead
> >>
> >> volatile unsigned long DC1 = 90;
> >>
> >> void IRQfunction(void)
> >> {
> >> DC1 = 20;
> >>
> >> }
> >>
> >> regards,
> >> Charles
> >>
> >> --- In lpc2000@yahoogroups.com, "ed_hage" <ed_hage@y...> wrote:
> >> >
> >> > Latest update:
> >> >
> >> > When I reassign a value to DC1 in the function it works, example:
> >> >
> >> > int DC1 = 90;
> >> >
> >> > void IRQfunction (void)
> >> > {
> >> > DC1 = 20;
> >> > PWM_MR4 = (PWM_MR0 * DC1) / 100;
> >> > ... etc
> >> >
> >> > Now I get a 20% DC, but when I comment out DC1 =20; I should
get a 90%
> >> > DC (as specified before) but then I get a constant high output!!
> >> > How can I get the global to work?
> >> >
> >> > (P.S. I also posted this question on the gnuarm group because I
> >> > suspect this may not be a typical LPC problem but maybe a
gnu-issue)
> >> >
> >> > > That's the point. I have it already running hard coded! I have a
> >> > > simular setup in a PWM_Init () function and I get great 5% DC
on myShow quoted textHide quoted text
> >> > > output-pin when I have the following:
> >> > >
> >> > > PWM_MR4 = (PWM_MR0 * 5) / 100;
> >> > >
> >> > > Also tried (DC1 defined in the function):
> >> > > int DC1 = 5;
> >> > > PWM_MR4 = (PWM_MR0 * DC1) / 100;
> >> > >
> >> > > and that works, but what I want and does not work is defining
> > DC1 as a
> >> > > global (outside the function) so I can change it with other
> > functions.
> >> > > How can I solve this problem
> >> > >
> >> > > (we have evolved to a problem that has nothing to do with floats
> >> > > anymore ;-} )
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> >