Showing posts with label Assembly language. Show all posts
Showing posts with label Assembly language. Show all posts

two servo walking robot using TI launchpad


       Hi, I bought two small servo motors last month. I was thinking what I can do with this two servo, since it is only two in number. Then I asked this to my friend Achu Wilson and he suggested me to try a four legged two servo walker and he shown a youtube video in which some one demonstrating it. Then I also got interested to make some thing similar to that. Then I started designing my walker using two servo and msp430 launchpad and at last it turned out even better than I thought it would.(See the video above). The servo controlling techinque used here is a little bit different compared to the usual hardware PWM, I used a circular buffer to save each servo position and o/p pin details. Only a timer compare interrupt is used for this. This is a common technique used for controlling more servo using a cheap microcontroller with limited hardware Timer-pwm modules. Using this software pwm(not a perfect pwm, but still it will work in the servo motors) techinque, I can control more servo motors like 4,5, 6 etc etc depending on the number of I/O pins. 
     Coding for this msp430 launchpad is done in asm just because I also want to refresh the msp430 assembly language programming. I used naken430asm assembler in linux for the purpose.

Photos:

Multitasking in AVR (A demo to run 7 tasks on an atmega32)

Hi,
Here I am introducing a simple task switching on an AVR as a demo... I did this just to get familiarized with the AVR assembly language programming.. Now I believe I learned it to an extent. Also I loves assembly language because it offers a great deal of power to use all of the features of the processor.

Introduction:
     Switching multiple tasks on a same CPU is the one of the major function of an operating system. What I did now is a time sharing multitasking (time multiplexing) on an AVR. Here an atmega32 is configured to use Round-Robin Multitasking. Round-Robin allows quasi-parallel execution of several tasks. Tasks are not really executed concurrently but are time-sliced (the available CPU time is divided into time slices). 
         Here, in my code below, it consist of 7 independent tasks and those are switched from one to another on a timer interrupt. 'May be' this could be considered as a simple & very very basic RTOS demo. Here I am mainly focusing on the core part ie the "task switching". 

Scheduling algorithm used: Round-robin (RR)
(one of the simplest scheduling algorithm)

Video demo:

Each led on the demo represents a task. Task1 (right most led, WHITE) is a software PWM task. All other tasks (2 to 7 from right to left) are toggling tasks. If you concentrate on a single LED, U may notice that the particular LED is toggling with a constant delay and is independent of others.

Working: 
 Here, total RAM (2KB) is divided among 7 tasks almost equally in such a way that each one get around 300 bytes of RAM space... This 300 bytes is considered

MULTITASKING IN MSP430

Task switching is one of the main function of an operating system. We could 'feel' a computer is doing multiple tasks at a time. The OS is actually switching the tasks one by one in a circular manner and executing each one for a small period of time and we feel it is doing all tasks at a time.... 

A small demo of multitasking in MSP430G2231 microcontroller:

     Here, three independent tasks are to be switched on every timer interrupt.  The CPU registers used in previous task is to be stored some where and the register values of the task to which it is switched is to be retained as before. Also, the switched task should run from where it is paused earlier.
Below is my asm code for running three independent tasks in an MSP430G2231 microcontroller. (just a demo, stack depth is very limited due to the limited RAM)

C and corresponding Assembly (MSP430G2231)

 Microcontroller programming become much simple if we use high level language like C. But it doesn't means that we could ignore the assembly language. In some situations, we might me forced to use a bit of assembly codes. Assembly language is a symbolic representation of a processor's native code. Using machine code allows the programmer to control precisely what the processor does. It offers a great deal of power to use all of the features of the processor. The resulting program is normally very fast and very compact. Using assembly programs, timings, for example, could be calculated very precisely.
     Here, I am just posting some basic C codes and their corresponding assembly (generated by msp430-gcc). By comparing the compiler generated assembly and the source C file, I hope, we will get a good idea of how the compiler effectively utilize the stack, various addressing modes, functions, global variables, local variables, pointers etc etc.
    For getting the disassembled view of the final hex code, we could use the msp430-objdump command. Disassembled view is the ideal one and it will contain each and every instruction from the reset address to the end of the program.