PID problem

Status
Not open for further replies.

kvrajasekar

New Member
Hi ,



1.I am using 16f72 to implement pid control operation.I can find the error,while reading feedback and input reference value.while calculating PID using error value, pid value becomes 16 bit wide.I am using ccp to generate pwm output.
2.I am using inbuilt ADC port(8-bit) for feedback.But the CCp using pid value is 16 bit wide.Is it possible to send the 16 bit value (or) i have to scale down it to 8 -bit? before sending to ccp.

I used the followin formula to find PID:

Proportional term:
P=Kp*Error
Integral term:
I=acc+Ki*error
acc=accumulative error

Differential term:
D=Kd*(Eprevious-Epresent)




Please help me on this...

regards,
Raja.
 
The PWM has only got 10 bits of resolution.

The duty cycle is:-

PWM duty cycle = (CCPR1L:CCP1CON<5:4>) •
TOSC • (TMR2 prescale value)

(data sheet page 41)

So to get 8 bit resolution all you need to do is leave CCP1CON bits 4 & 5 at zero and put the duty cycle that you want in CCPR1L

However, you might be better to do you calculations to 16 bits and just use 8 bits for input and output. The way that you do that depends on what language you are writing in.
 
Hi Mr.Diver300

Thanks for the reply.

Sorry,I forgot to tell you,I am using CCP in compare mode ,not in PWM mode.

Can you please tell me how to scale down 16-bit to 8-bit value.or can i divide the 16-bit value by 256...
 
Last edited:
can you not just shift the bits eg. 8bit = 16bit >> 8 to scale down the number?

i guess that depends on what you program it with.
 
Sorry - i cant program naturally in asm, I only do very short routines that need to be very fast, even at that I need to sit with a book on my knee.

Im sure there are loads of asm programmers who may be able to help with this
 
Try:

movlw high PIDValueHere

EDIT:
Found that in the HELP under:
MPASM Assembler
---Expression Syntax and Operation
-------Arithmetic Operators and Precedence
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…