counting at 600Mhz

Status
Not open for further replies.
Code:

int led = 13;

void setup() {
// put your setup code here, to run once:

pinMode(led,OUTPUT);

digitalWrite(led,LOW);
}

void loop() {
// put your main code here, to run repeatedly:

unsigned long ii=1200000000000;
long jj = 1;
// 536870912
// 1073741824
// 4294967296
// long aa=0;


while(jj>0){

digitalWrite(led,HIGH);
//delay(500);
for (unsigned long i = 0 ; i < ii ; i++)
{
// aa=1;
}//end of i

digitalWrite(led,LOW);
//delay(500);
for (unsigned long j = 0 ; j < ii ; j++)
{
// aa=1;

} //end of i

}// end of while
}// end of loop()



I tried to count at 600Mhz ( or as fast as allowable). When I ran this code with the delays active and the counting loops commented out, it worked fine. Using the count loops, the LED lit bright for two seconds and just went to a continuous dim. 1.2 E9 counts should be 2 seconds ( at least) for up and down. Any help is appreciated.

Question 2 does i++ work wit long long int's?

Thanks!

Tim
 
Indeed, the compiler is very aggressive about deleting code it knows has no result actually used. It's rarely an issue in practical usage, but we see it come up all the time with "trivial" tests and simple attempts at benchmarking.

Also, unsigned long is 32 bits on Teensy. The maximum value is 4294967295. If you want to represent a very large number like 1200000000000, you need 64 bits. Best to use "uint64_t" as the type, so you can know for sure a 64 bit integer really is used.
 
Indeed, the compiler is very aggressive about deleting code it knows has no result actually used. It's rarely an issue in practical usage, but we see it come up all the time with "trivial" tests and simple attempts at benchmarking.

Also, unsigned long is 32 bits on Teensy. The maximum value is 4294967295. If you want to represent a very large number like 1200000000000, you need 64 bits. Best to use "uint64_t" as the type, so you can know for sure a 64 bit integer really is used.

Thanks for that. You're right about "trivial code", but I grew up old school where you test all code as you build up to a project. I'll try the uint64_t as well.
 
Try using "unsigned volatile long"
"volatile unsigned long" please - its confusing to mix up qualifiers with the type like that. Qualifiers, then the type, is
the norm and compatible with using typedef too :)
 
Status
Not open for further replies.
Back
Top