Error message

Deprecated function: Optional parameter $translation_node declared before required parameter $language is implicitly treated as a required parameter in include_once() (line 1439 of /home/gpstron/public_html/site/includes/bootstrap.inc).

Electromagnetic levitation with microprocessor control

Electromagnetic levitation with microprocessor control using PIC16f886. It uses hall sensor for feedback for measuring the distance between the coil and the levitating magnet. 

 

 

Here is the schematic using compatible PIC16f882 microprocessor :

English

Comments

We are implementing a project which is similar to yours, A magnetic levitation system. We have implemented a design which is able to suspend a magnetic body in air by push-pull configuration using hall effect sensors. We have plans to proceed and make a device which can provide one dimensional motion of the body. So it will be much helpful if you can share us the schematic and source code

..We are a group of engineering students

Regards
Raj

I posted the old version of the schematic. The source code simply read the value of the hall sensor and with PID, or only proportional way calculate the value for the PWM output to the transistor.
Now I am working on other idea of using two hall sensor one on the bottom of the coil and one on the top. The extra one on the top will show the error which coil add to the sensor on the bottom which in fact must measure ONLY the magnetic field of the levitating magnet.

Regards
Martin Nikiforov

Dear DIY,
Could you upload the code? I'm also focusing on it but I have problem with coding.
Thanks for your hands!

#include "d:\shemi\levitator 16f886\levitator886.h"
#include "STDLIB.H"
int pos_i=0;
int Kp=7,Ki=1,Kd=1;
int16 potenciometer;
int16 set_position=750;
int16 position;
signed int16 PWM_d=100;
signed int16 error_now;
signed int16 error_last=0;
signed int16 integral_error=0;
signed int16 iMAX=50,iMIN=-50;
signed int16 differential_error=0;
signed int16 dMAX=10,dMIN=-10;
void settings();
#int_EXT
void EXT_isr(void)
{
//delay_us(100);
if(!input(Pin_b0)){
// setup_timer_2(T2_DIV_BY_1,255,1); //16khz

set_position=position;
output_toggle(PIN_b3);
}
return;
}

#int_AD
void AD_isr(void)
{
//pos_i++;
//if(pos_i==5)pos_i=1;
position=read_adc(ADC_READ_ONLY);
return;
}

#int_RDA
void RDA_isr(void)
{

}

void main()
{
// setup_oscillator(OSC_8MHZ);
delay_ms(100);
setup_adc_ports(sAN0|sAN1|sAN2|VSS_VREF);
setup_adc(ADC_CLOCK_DIV_8);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);

setup_timer_2(T2_DIV_BY_1,255,1); // ~16khz
setup_ccp1(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_PWM_H_H|
CCP_SHUTDOWN_ON_INT0|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L);
setup_ccp2(CCP_PWM);
set_pwm1_duty(500);
set_pwm2_duty(800);
delay_ms(1000);
port_b_pullups (TRUE);
setup_comparator(NC_NC_NC_NC);
delay_ms(200);
// enable_interrupts(INT_EXT);
enable_interrupts(INT_AD);
delay_ms(200);
enable_interrupts(GLOBAL);

int i;
int8 analog_input=1; // 0-potentiometer 1-hall
set_adc_channel(analog_input);
delay_us(30);

// settings();
while(true){
output_toggle(PIN_B5);
//if (analog_input==0) {potenciometer = read_adc()/2;analog_input++;}
// position[0]=0;
// for( i=1;i<5;i++){
// position[0]+=Position[i];
// }
// position[0]=position[0]/4;
// set_adc_channel(analog_input);

//printf("%4Ld %4Ld %4Ld \r\n",error_now,position,PWM_d);
//delay_ms(20);
error_now=position-set_position;

//if(error_now>(error_last+dMAX))error_now=error_last+dMAX;
//if(error_now<(error_last-dMIN))error_now=error_last-dMIN;

// integral_error+=(error_now/4);
// if(integral_error>iMAX)integral_error=iMAX;
// if(integral_errordMAX)differential_error=dMAX;
//if(differential_error1000)PWM_d=1000;

// setup_ccp1(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_PWM_H_H|
//CCP_SHUTDOWN_ON_INT0|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L);
//set_pwm1_duty(position[0]);// debug na pwm
set_pwm1_duty(PWM_d); // debug na pwm
read_adc(ADC_START_ONLY);
delay_ms(1);
error_last=error_now;

// delay_ms(250);
}

}
void settings(){
char setting_string[20]="";
char *ptr;
long timeout;
timeout=0;
//printf("settings?\n\r"); //stop if there is no terminal
while(!kbhit()&&(++timeout<50000)) delay_us(100);
if(!kbhit()) {
printf("set_position=%Lu Kp=%u Ki=%u Kd=%u \r\n",set_position,Kp,Ki,Kd);
// for kp kd float - printf("set_position=%Lu Kp=%g Ki=%g Kd=%g \r\n",
//set_position,Kp,Ki,Kd);
delay_ms(2000);
return;
}
gets(setting_string);
printf(setting_string);
setting_string="";

printf("set_position:");
gets(setting_string);
set_position=strtoul(setting_string,&ptr,10);
printf(setting_string);

printf("Kp:");
gets(setting_string);
Kp=strtof(setting_string,&ptr);
printf(setting_string);

printf("Ki:");
gets(setting_string);
Ki=strtof(setting_string,&ptr);
printf(setting_string);

printf("Kd:");
gets(setting_string);
Kd=strtof(setting_string,&ptr);
printf(setting_string);
printf("set_position=%Lu Kp=%u Ki=%u Kd=%u \r\n",set_position,Kp,Ki,Kd);
//for float parameter - printf("set_position=%Lu Kp=%g Ki=%g Kd=%g
// \r\n",set_position,Kp,Ki,Kd);
delay_ms(2000);
}

You can just remove "//" from the lines you want to make the controller type you like - PID, PD, PI. Also you must tune it with parameter kp ki kd for your system.
Here is configuration levitator886.h file

#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES PUT //Power Up Timer
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOWRT //Program memory not write protected
#FUSES BORV21 //Brownout reset at 4.0V
#FUSES RESERVED //Used to set the reserved FUSE bits

#use delay(clock=25000000)
#use rs232(baud=38400,parity=N,xmit=PIN_B7,rcv=PIN_B6,bits=8)

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.