-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing frequency
doesn't change simulation speed
#201
Comments
It's not supposed to. simavr doesn't /try/ to run at simulated speed /unless/ you use a timer and sleep() the CPU. Otherwise, it has no way of really 'slowing down' the instruction flow compared to the host. if you use a timer interrupt, and sleep() the CPU in your main(), then simavr knows it can try to sync itself to that speed and will 'sleep' the simulation accordingly. It's not perfect, and is not 'smooth' (the avr code will STILL run at full speed when not in sleep() mode; but it allows rather good approximation. |
node that your _delay_ms(1000) is not /really/ a delay at all, it's a spinloop, simavr has no idea it's spinlooping for no reasons. |
OK, so I've changed my AVR code to use a timer interrupt instead:
Then I changed the main loop to sleep instead of busy-waiting:
And now I'm getting nice 1Hz blinking. Thanks! |
Well done, it's actually a nice test case, would you care to convert it to a wiki page? That methos is also vastly better way of using the AVR anyway, as it'll save power when sleeping. You can also use the asynchronous clock of the avr by using an external 32.7k crystal and use even less power as you will be able to use the deep sleep mode as well. I've made projects using picoamps using that system! |
I have the following test program:
I compile it with
This results in an
image.elf
file that I then load into the following program that uses SimAVR:Problems:
f.frequency
doesn't change the speed at which the message is printedThe text was updated successfully, but these errors were encountered: