• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Inverted Pendulum on a Cart

Not open for further replies.


New Member
Hi Guys

This is my first post and very much fascinated by this forum. You people are just great. I am working on my project "Inverted Pendulum on a Cart" and have just started pulling up my hairs. I am using PIC 16F877A with 20MHz crystal and assembly language. I got following few questions.

1) The result generated by A2D from my angle measurement potentiometer is 10bit (NumH & NumL). I am doing left justified and igonoring the register NumL to make it 8bit to make it simple to deal with.
Then I subtract it from my reference signal which is zero which gives me error signal which is a signed number.
Then I need to multiply this error signal with proportional value which is unsigned number (Please note I am ignorinng Integral and derivative term at the moment).
What command can I use to make proportional value a signed number as I suppose we can multiply signed number by signed number only. Can anyone please recomend any good routine for multiplication in assembly?

2)The result achieved from this multiplication of proportional value and error signal is 16bit. In my PWM assembly code for motor, I am using 0-127 for forward direction and 128-255 for reverse direction.
How can I use this 16bit data generated from multiplication to give command to my motor. If it was only 8bit it was very easy that I simply check the 8th bit and based on that give direction to drive motor either in forward or reverse direction.

3) If someone can please shed some light on how can I implement integral and derivative terms of PID using assembly.

Please accept my thanks in advance. At the moment my project looks as below:-



Well-Known Member
Hi. Nice cart.

The things you seem to be struggling with are specific to the variables and not procedural, ie you know how to do the job but are finding it is hard to do that job in assembler.

Have you considered downloading a free C compiler like MikroC eval version or the Hitec-C free student version? That will make it a breeze to use 16 or 32 bit signed/unsigned vars and convert between them too. There are also a lot of C code examples for balancing robots which might help you too, I don't think you will find many examples in assembler.
Not open for further replies.

Latest threads

EE World Online Articles