# Implementing fuzzy logic in PIC18F4431 with MPLAB using c language programming

Status
Not open for further replies.

#### Faniah

##### New Member
Hi,

My project is 'optimum solar cell implementation using dc-dc boost converter controlled by fuzzy logic controller'. I'm using MPLAB IDE for programming the PIC18F4431. I really don't have any idea about the c programming for fuzzy logic controller. I had done the inference rules in Matlab fuzzy logic toolbox. The input is error, E and change in error, CE. The output is the duty ratio, D of the boost converter. Below is the rules.

For example, If E is NB and CE is ZE then D is NB.
So any examples of fuzzy logic controller c programming which are related to this project will be helpful to me. Thank you.

#### ClydeCrashKop

##### Well-Known Member
I don't know fuzzy logic but looking at your inference rules, I would treat it like a quadrature decoder. Have a function for each "E" condition and loop there waiting for a change. Then you can assign that value to your variable, return to Main(), which would call function for the new "E" condition and wait for a change.

Code:
void EisNB (void)
{
while(1)                // endless Loop
{
if(CE == ZE)
{
D = NB;
return ;
}

if(CE == PB)
{
D = NS;
return ;
}

if(CE == PS)
{
D = ZE;
return ;
}
} // while(1)
}// EisNB (void)

Last edited:

#### Faniah

##### New Member
Thank you. I'll try

#### Faniah

##### New Member
What sensor that can be use to sense the voltage and current separately for solar cell? Anybody help me.

#### ClydeCrashKop

##### Well-Known Member
That looks like a good chip but it has a lot of errata.
PIC18F2x31, 4x31 Data Sheet
SSP Module Errata
PIC18F2x31, 4x31 Rev A2 Silicon Errata
PIC18F2x31, 4x31 Rev A3 Silicon Errata
PIC18F2x31, 4x31 Data Sheet Errata
Timer1 Errata
PIC18F2x31, 4x31 Programming Specification
You have up to 9 ADCs. You can use a voltage divider to bring you voltage down to a compatible amount. Use the Search>more option to search the microcontroller section of this forum for "measure amps". It says the word ADC is too short so it won't search for it.
You will probably use a shunt. This thread may help.
http://www.electro-tech-online.com/...y-on-lcd-using-pic18f4520.100480/#post-820939

#### NorthGuy

##### Well-Known Member
What sensor that can be use to sense the voltage and current separately for solar cell? Anybody help me.
For voltage, simply use voltage divider. For current, it's best to use a shunt/resistor. Both will go to ADC.

For your algorithm, simply use 2-dimensional lookup array - int[5][5]

#### Faniah

##### New Member
I want sensor to track the voltage and current of the solar cell which will be send the signal to PIC for fuzzy logic programming.

#### NorthGuy

##### Well-Known Member
I want sensor to track the voltage and current of the solar cell which will be send the signal to PIC.
Most PICs have built-in ADCs, which can be used to measure voltage, so you do need a separate device to do measurements.

#### Faniah

##### New Member
Ok..thank you for the info.

Status
Not open for further replies.