Reply by Klaus Vestergaard Kragelund April 10, 20042004-04-10
"Hans-Bernhard Broeker" <broeker@physik.rwth-aachen.de> wrote in message
news:c59dlp$7po$3@nets3.rz.RWTH-Aachen.DE...
> Klaus Vestergaard Kragelund <klauskvik@hotmail.com> wrote: > > > """""""" > > #define SYSCLK 10000000 // SYSCLK frequency in Hz > > #define SYSCLK_MINUTE 600000000 // (600E6) > > #define SYSCLK 10000000UL > #define SYSCLK_MINUTE (60*SYSCLK) > > would be easier to maintain. The UL suffix might even suffice to make > your problem go away. > > > unsigned long TimerCount; > > unsigned int SampleRate; > > unsigned int is a 16-bit type on that platform. That's your problem > (along with the fact that Keil doesn't strictly follow ANSI integer > promotion rules unless you request that explicitly) > > > TimerCount = SYSCLK_MINUTE / SampleRate; > > """""""""" > > If the suffix doesn't do it already, you may have to case SampleRate to > (unsigned long) here. >
Thanks Hans Well, it turned out that wasn't the problem. The Debug window was not reset - so it was specified as a 16 bit value there - no problem when I fixed the representation to a 32 bit value :-) Cheers Klaus
Reply by Hans-Bernhard Broeker April 10, 20042004-04-10
Klaus Vestergaard Kragelund <klauskvik@hotmail.com> wrote:

> """""""" > #define SYSCLK 10000000 // SYSCLK frequency in Hz > #define SYSCLK_MINUTE 600000000 // (600E6)
#define SYSCLK 10000000UL #define SYSCLK_MINUTE (60*SYSCLK) would be easier to maintain. The UL suffix might even suffice to make your problem go away.
> unsigned long TimerCount; > unsigned int SampleRate;
unsigned int is a 16-bit type on that platform. That's your problem (along with the fact that Keil doesn't strictly follow ANSI integer promotion rules unless you request that explicitly)
> TimerCount = SYSCLK_MINUTE / SampleRate; > """"""""""
If the suffix doesn't do it already, you may have to case SampleRate to (unsigned long) here. -- Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain.
Reply by Klaus Vestergaard Kragelund April 10, 20042004-04-10
Hi

Well, this is driving me nuts. I'm using Keil uVision C51 compiler for a
Cygnal 80C51F302 device

This is the code:

""""""""
#define SYSCLK   10000000  // SYSCLK frequency in Hz
#define SYSCLK_MINUTE 600000000 // (600E6)

unsigned long TimerCount;
unsigned int SampleRate;

TimerCount = SYSCLK_MINUTE / SampleRate;
""""""""""

If SampleRate is 6 for example, the result of TimerCount is 1525

When I would suspect it should be 100000000 (10E6)

Where's my mistake?

Thanks

Klaus