Electronic – arduino – How to use avrsim to simulate Arduino

arduinosimulation

I found very nice open source avr emulator (this one.) Since there is uart emulation implemented it can simulate Arduino.

I have some problems with the "board_simduino" example.

I hooked up virtual leds to port B (pins 8-13) – http://gitorious.org/~viroos/simavr/viroos-simduino-simavr/commit/bfaeac1e61f1d6678b3daab7fede9a783d01c098, and they work.

But serial connection looks broken. I can upload sketch (I added ,link=/dev/ttyUSB0 to socat command for that), but after that communication stops working. For example I can upload "physical pixel" sketch but I can't turn on leds. I tried to connect using serial monitor in buily in IDE and from pySerial. It looks like commends are being ignored.

Also in "blink" sketch in the main loop:

void loop()
{
 digitalWrite(ledPin, HIGH);   // set the LED on
 delay(1000);                  // wait for a second
 digitalWrite(ledPin, LOW);    // set the LED off
 delay(1000);                  // wait for a second
}"

I have to remove delay(1000); command because they hang the emulator.

I will appreciate any help. Most important form me for now is uart fixing (run "physical pixel" sketch.)

Best Answer

While I haven't use a hardware simulator for a while, it think what s happen is something like this.

Each clock cycle of the AVR is simulated which takes multiple clock cycles on the host PC. Hence time on the simulated AVR is running slower than real time. This could explain why the delay loop would appear to hang the AVR simulator.

A similar scenario could be the case with the serial port.

Personally, I'm not sure if the simulating modern processors with flash memory is productive as it's quicker to just load the program into the system and "let it run" to see what happens.