Yes, im mad and crazy.
but I have implemented a very basic PID loop to control the position of a motorized P&G fader (PGFM3200).
this runs fairly well on 8mhz 28x2. however my h-bridge keeps on overheating... i think its because of the pwm frequency, but my pic squeels if i lower the pwm frequency.
its a bit sluggish around the target area. this is because the integral term is missing. however, the integral term didnt work at such low sample rates, creating oscillations.
First off, any optimisations or improvements? to make it run faster at 8mhz
most importantly tho, where can i find a 40mhz crystal to clock the 28x2 up to its potential?
but I have implemented a very basic PID loop to control the position of a motorized P&G fader (PGFM3200).
Code:
setfreq m8
symbol kP = 40 '/20 gain of 2
symbol kD = 10 '/20 gain of 0.5
symbol correction = w0
symbol PrevErr = w1
symbol Err = w2
symbol ErrSum = w3
symbol temp = w4
'where we wanna be
symbol target = b20
'just to make it do something
symbol counter = b21
'setup pwms
pwmout c.1, 49, 0
pwmout c.2, 49, 0
target = 0
start:
'something to make it move
inc counter
if counter > 128 then
target = 220
else
target = 100
end if
'get current position
readadc 0, Err
'calculate error
Err = target - Err
'proportional
correction = kP * Err
correction = correction / 20
'differential
temp = PrevErr + Err
temp = temp * kD
temp = temp / 20
correction = correction + temp
PrevErr = Err
temp = correction MAX 200 'correction modulous
if temp > 8 then 'stops low level movements
if correction > $1000 then 'negative correction
pwmduty c.2, temp
pwmduty c.1, 0
else
pwmduty c.1, temp 'positive correction
pwmduty c.2, 0
end if
else
pwmduty c.1, 0
pwmduty c.2, 0
end if
goto start
its a bit sluggish around the target area. this is because the integral term is missing. however, the integral term didnt work at such low sample rates, creating oscillations.
First off, any optimisations or improvements? to make it run faster at 8mhz
most importantly tho, where can i find a 40mhz crystal to clock the 28x2 up to its potential?