Simulating arduino and atmega

 This is a simple update of the project I'm working. I am attempting to build a simulation model for an entire atmega mcu, that can be inegrated with ngspice (an open source circuit simulator). The idea to take the binary file in the .hex format , parse it to get the instructions and then execute the program instruction by instruction to get a response (similar to a processor emulator). In this post I am giving a demo of the work that has been done till now.


I will in this post, demonstrate how I am able to get a pwm pulse from the MCU and use it to drive the motor. The system being simulated is as : 




The c program used is as follows : 


define F_CPU 1000000UL

#include <xc.h>
#include <avr/io.h>
#include <util/delay.h>


int main(){

DDRD = 0xFF;
TCCR0A = 0x81;
TCCR0B = 0x01;
OCR0A = 0xFE;

return 0;
}


From this I get a hex file using the xc8 compiler for avr. I use that file to get the set of instructions in the program and execute them step by step : 

The complete log of the instructions is in the log.txt file attached, a brief screenshot is attached here : 



The lines after the program counter are the instructions that are executed (with the "act" prefix added. 


I was able to integrate this, with a model for the pwm counter of avr, which generates the pwm signals as (as per the register values ).  (this will be the output on PD4 (OC0A) pin of atmega).



This pwm signal can then be integrated to a model for an h -bridge or a motor to give the response. 


I used the model of a motor described here : motor model


When this pwm signal is fed into the motor it gives us the required response. The response that I get is : 

 


 

This is the response similar to that of a motor starting from rest. 

 

This is a demonstration of an ongoing project, if you need some simulations related to embedded systems, control systems or electronic systems in general please feel free to contact me.

email : chittoraharsh98@gmail.com

phone : 946069028.




Comments

Popular posts from this blog

Simulating a motor in ngspice

Counting pulses in Arduino (without interrupts or loops)

Embedded system simulations using tessim