Posts

Showing posts with the label motor

Counting pulses in Arduino (without interrupts or loops)

Image
 In this post, I will talk about how to count pulses in Arduino without using any interrupts or loops. This method can come in handy when the controller is handling a lot of task which can either cause it to miss some counts or introduce some unnecessary delays if some checks are included.  Even when using interrupts, it will have to interrupt a program in execution in order to increment a count. This will obviously cause delays for the rest of the program.  In this blog, I will be using the built in timer/counter module of Arduino for the purpose. More details about this module can be found in the atmega328p datasheet ( link ) (in chapter 14,15 and 16).  I will provide a basic introduction, mainly the three registers (TCCR0A, TCCR0B and TCNT0) that will be of use to us.  Introduction  A basic function of the timer counter is to (as the name suggests) "count". It increments the counter (the value in the TCNT0 register) whenever it encounters a clock. The cl...

Simulating a motor in ngspice

Image
 Motors and actuators are an integral component of any robotics project.  In this post I will describe how a simple pmdc motor can be simulated using xspice and ngspice.  Modelling of a PMDC motor A simple model of a pmdc motor is given below :  Model f a PMDC motor  The electrical characteristics (current voltage and back emf) can be modeled by the following equation :-   where Ra is the armature resistance, La is the inductance of the coil, Vs the applied voltage and Vb is the back emf of the motor.  The mechanical characteristics of the motor are :-    Jm is the moment of inertia, Bm is the friction constant , Tm is the torque applied by the motor and TL is the external load torque.    In the above two equations we can substitute :    Vb = k w(t) Tm = k i(t) where w(t) is the angular velocity and i is the armature current of the motor. In order to model these in xspice code model these equations were discretized a...