OpenServo.com Forum Index OpenServo.com
Discussion of the OpenServo project
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How's my thinking

 
Post new topic   Reply to topic    OpenServo.com Forum Index -> Software
View previous topic :: View next topic  
Author Message
mikewardlow



Joined: 16 Mar 2006
Posts: 42

PostPosted: Thu Mar 30, 2006 5:33 pm    Post subject: How's my thinking Reply with quote

Hows my thinking??

Timer0 [1us] interrupts every 512us using 1:2 prescale...

At each Timer0 int I start an ADC conversion which takes about 26us.....

When the conversion is complete [conversion interrupt] I save the 10 bit value of the feedback pot...,, and allow a pid loop to run.....which will set/clear the cw/ccw and load ccpr1l[pwm] counter.....This looks like it should be ok....


But thinking about this!!!

I have 1/512us = 2khz UPDATE loop running,,,so any changes I make
to cw or ccw will act like 2khz pwm with the length of cw/ccw being the dutycycle as well as direction control.

Therefore making changes to the dutycycle of the hardware CCP is probably only affecting drive current...and I really have a pwm of some period ruuning within a 2khz pwm loop....

Can sombody tell me what this is telling me ???????
Back to top
View user's profile Send private message Send e-mail
mpthompson



Joined: 02 Jan 2006
Posts: 650
Location: San Carlos, CA

PostPosted: Thu Mar 30, 2006 6:14 pm    Post subject: Reply with quote

I followed you on the first half of your post, but I am not sure what the following really means:

Quote:
I have 1/512us = 2khz UPDATE loop running,,,so any changes I make
to cw or ccw will act like 2khz pwm with the length of cw/ccw being the dutycycle as well as direction control.

Therefore making changes to the dutycycle of the hardware CCP is probably only affecting drive current...and I really have a pwm of some period ruuning within a 2khz pwm loop....


Just to recap, you are taking ADC samples of your potentiometer every 512 uS for a 2 KHz sample rate. The ADC position value is fed into your PID function -- which implies it is producing cw/ccw values at a 2 KHz rate as well. The PID function produces your cw/ccw values that are then set in your hardware timer to produce a PWM value of the correct duty cycle. These updates to your timer to alter the PWM duty cycle are occuring at a 2 KHz rate as well.

You will want the timer frequency to be some modest multiple of the 2Hz sampling/PID/update frequency. For example if you use a PWM timer frequency of 10 KHz each ADC sample will result in about 5 PWM cycles of the calculated duty cycle.

Something to remember is that on the AVR (and I assume other architectures as well) the 8 bit timer will actually be set for a 256 multiple of the desired PWM frequency. This is because the 8 bit timer is constantly counting up form 0 to 256. The pwm signal is set when the timer crosses the 0 threshold and reset when timer crosses the dutycyle threshhold giving you the ability to change the dutycyle with an 8 bit resolution.

-Mike
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
mikewardlow



Joined: 16 Mar 2006
Posts: 42

PostPosted: Sat Apr 08, 2006 9:11 am    Post subject: Reply with quote

;------------------------------------------------------------------------------
; misc comments:
; currently the CW / CCW signals change at the T2 interrupt rate [100us]
; The pid rate is T0 int [currently 512 US] 1953 hz
; therefore cw/ccw would be same rate??? only chopped up by pwm hdw
; conclude: computing prop err
; set sign to select cw/ccw the set cw/ccw
; if allowed [rather than T2 int]
; this immediately would drive servo
; [ie] prop only control ????
; so How do I get the stopping resolution better???????
;------------------------------------------------------------------------------

I'm having problems utilizing the pwm ccp pic hdw....
I am getting insufficient control/drive...
I must be missing something in Colin's pid8.asm
The big difference I'm trying to use 1 pwm signal anded with direction..
Colin use 2 pwm's 1 cw the other ccw.......
Back to top
View user's profile Send private message Send e-mail
mikewardlow



Joined: 16 Mar 2006
Posts: 42

PostPosted: Sun Apr 16, 2006 2:22 pm    Post subject: Test computing PID result for PWM Reply with quote

I was trying to get some insite to what pid returns I would get if
the Desired position stayed at 0 and the current position changed
[ie] arm forced to move ....so I tried this Qbasic pgm ...

I can make no sense out of pidFinal........

Can this be done and get meaning full results ???????????












kp = 10 ' 5-10
ki = 5
kd = 20

pidI& = 0
pidIx& = 0
pidLast& = 512 + 32 ''initial pidlast = 1st current

Imax& = 32000
Imin& = -32000

'Syserr = DesiredPos - CurrentPos
DesiredPos& = 0 ' neutral
PRINT ""==========================================================""

FOR CurrentPos& = 512 TO -512 STEP -32 ' 10 bit error value

Syserr& = DesiredPos& - CurrentPos&

pidP& = Syserr& * kp

pidI& = pidI& + Syserr&
IF pidI& > Imax& THEN pidI& = Imax&

IF pidI& < Imin& THEN pidI& = Imin&

pidIx& = pidI& * ki
pidDx& = CurrentPos& - pidLast&
pidD& = pidDx& * kd
pidLast& = CurrentPos&

pidFinal& = pidP& + pidIx& + pidD&

PRINT CurrentPos&; ""/""; Syserr&; TAB(14); pidP&; TAB(22); pidI&; ""/""; pidIx&; TAB(3Cool; pidDx&; ""/""; pidD&, pidFinal&; ""/""; INT(pidFinal& / 256)

NEXT CurrentPos&

END
Back to top
View user's profile Send private message Send e-mail
andylippitt
Site Admin


Joined: 02 Jan 2006
Posts: 155
Location: Denver, CO

PostPosted: Sun Apr 16, 2006 3:56 pm    Post subject: Reply with quote

The only thing I can point out is a mistake I've made more than once. Your kD term should be negative.
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    OpenServo.com Forum Index -> Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group