# Inverted Pendulum on a Cart

Status
Not open for further replies.

#### mtariq85

##### 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:-

#### Mr RB

##### 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.

Status
Not open for further replies.

Replies
0
Views
1K
Replies
4
Views
838
Replies
4
Views
6K
Replies
1
Views
2K
Replies
3
Views
2K