Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LFR with PID

Status
Not open for further replies.

Attachments

  • A113051112.pdf
    726 KB · Views: 509
HI,

What will be difference in PID and fuzzy logic control?
PID controller can be tuned using well known methods to match your requirements. Fuzzy controller is more trial and error type of controller.. You'll just have to experiment with it.
 
At 20MHz you get a 5MHz cycle.... Thus 200nS time as 1/5000000 = 0.0000002.

So count the value in PR2 ( this is the pre-load of the timer ) 255 * 0.0000002 = 0.000051 or 51μS... That is 19607.84Hz or 19.60784KHz

If you pre-scale then you multiply this by 4 and 16 respectively

If you post-scale then you multiply the result of the previous calculation by 1 though 16 respectively.


So you are interrupting every 51μS as you have a maximum count and no scaling atall...

If i use pre-scale of 1:2 then 200nS x 2, right ??
if post-scale of 1:2 then 51us x 2, right?
according to timer2 block diagram TMR2 output what is this?
 
So, which is better?

It depends what you are doing and what you consider being "better". Using a fancy control system does not automatically make your system good. You'll have to have some knowledge and skills to make it work.

If you do not know how PID controller works, or how to tune it, then it is better not to use PID controller. Same applies to fuzzy controller.. if you do not know how it works, do not use it. You can study and try both and then decide which one was better.

It is possible to make fuzzy controller behave like a PID controller, but it is impossible to make PID controller behave like a fuzzy controller. So, fuzzy controller gives you more options, but there are no systematic methods to tune fuzzy controller. PID controller is popular because there are many well known methods to tune it.. and you can prove mathematically that the controller performs up to certain requirements.
 
Last edited:
OK, I have changed it control freq as PWM is also same. ~20KHZ

Code:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
int ReadADC(unsigned char ch);
void interrupt ISR() 
  {
  if(TMR2IF){   
  n3 = ReadADC(0); 
n2 = ReadADC(1);//sensor 2
if(n2<=b&&n3<=b){//str
  CCPR1L = 95 ;
  CCPR2L = 95 ;
RC4=1;//forward a
RC3=0;
RC0=0;//forward b
RC6=1;
}
}
  TMR2IF = 0;
  }
void main(void){
  ADCON0=0b01000001;//000 = channel 0, (RA0/AN0)
  ADCON1=0b10000000;
TRISC=0X00;
unsigned int b;
TMR2IE = 1;              // enable timer 2 interrupt
  PEIE = 1;              // enable peripheral interrupt
  GIE = 1;
  int n4;
  int n1;
  int n2;
  int n3;
  PR2 = 255 ;
  T2CON = 0b00000100 ; 
  CCP1CON = 0b00111100;
CCP2CON = 0b00111100; 
while(1){
RC4=1;
RC4=0;
}
}
 
I've just done a dead simple PID control just using P...

Not more than 8 lines of C code..... I'm quite impressed with its response... I'm designing a throttle system for large cranes.... BEFORE you ask.. No!! you can't have the code....

Point is... I'ts easy to setup...
 
I was reading the old thread of my for PWM:
Period = 1 / (TOSC * 4 * ( PR2 + 1) * (T2CON Pre scaler) )

Period = 1/ ( 0.2μS * 4 * 56 * 1 ) = 22.32Khz
if PR2 = 0b11111001 ;
how we get 56 here??
Point is... I'ts easy to setup...
can you tell me about control freq of it and pwm freq, and tell me any easy setup to learn then lFR or any thing else for starting it..
 
and tell me any easy setup to learn then lFR or any thing else for starting it..

Easiest way is to try thinking on your own. The hardest thing you can do is just copy other peoples work and trying to get it working without thinking.

Line follower is a very simple system. You do not need pid control or any other fancy systems. If the line is going left.. steer to the left, if the line is going right, steer to the right.
 
I was reading the old thread of my for PWM:

if PR2 = 0b11111001 ;
how we get 56 here??

The equation is in the datasheet.... People choose 20khz+ so the motor whine cannot be heard..

can you tell me about control freq of it and pwm freq, and tell me any easy setup to learn then lFR or any thing else for starting it..

PID checks for error... then corrects the error aggressively if the error is too large or subtly if the error is small..
You need to track the line so when the robot leaves the line you know how to correct... Usually two sensors track the changes of direction.... If the line goes left the robot should go left.....
 
I was working on LFR with PId as Mr T said the control freq of uC and PWM should be same for that in post#46 i have updated both are nearly 20KHZ PWM and control loop freq.
 
lol
IF (temperature is "cold") THEN (heater is "high")

Fuzzy_control_-_centroid_defuzzification_using_max-min_inferencing.png
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top