Shop OBEX P1 Docs P2 Docs Learn Events
Having trouble with making new cogs and the PID — Parallax Forums

Having trouble with making new cogs and the PID

grasshoppergrasshopper Posts: 438
edited 2008-09-17 21:56 in Propeller 1
I am still having trouble making my own cogs. Cant seem to get my head aroung the whole thing. I have no troubles sending data to a cog and starting it up, but when i need to get data from a cog - well i get lost.

here is my PID cog that i tried to make

[code]

'' PID.spin (Under construction)

OBJ

f : "FloatMath"

VAR

long cog
long kp, ki, kd, sp, off, Amax, Amin
long a, tp, Ep
Long in

PUB Start (_Kp, _Ki, _Kd, setPoint, offset, maxArea, minArea) : okay
'' Set vdalues of kp, ki, etc.
Stop
okay := cog := cognew(Runit(in), @kp) + 1
longmove(@kp, @_Kp, 7)

PUB stop

'' Stop serial driver - frees a cog

if cog
cogstop(cog~ - 1)

longfill(@kp, 0, 7)


Pub RunIt(in) <
Problem is here i think _

Calculate(In)

PUB calculate(in) :out | temp, E, P, I, D, da, t, dt, Et

'' Returns PID (out)put based on (in)put and stored values.

' Calculate Δt = [noparse][[/noparse]cnt(now) - cnt(previous)] / clkfreq
t := cnt ' t(now) = cnt
dt := t - tp ' Δcnt = t - tp
dt := f.fDiv(f.FFloat(dt), f.FFloat(clkfreq)) ' Δt = Δcnt

Comments

Sign In or Register to comment.