Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] interfering if signals while LCD running in 18f4431....

Status
Not open for further replies.

prem123

Newbie level 5
Newbie level 5
Joined
Jul 11, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,380
i am generating pwm signals in 18f4431. duty of those signals are controlled by an analog input. but when lcd display is included in to the program, the controlling task is not performed correctly.
what can be the reasons??
 

here is the code...

char *text7 = "OVER CURRENT";
char *volt[1];
char *freqncy[1];

int j=0;
unsigned int vol;
unsigned int freq;
unsigned int tem;

void Voltage(int vol);
void Frequency(int freq);
void Temperature(int temp);
void Move_Delay();
void sectors (int sector);
void duty(unsigned int pwm1,unsigned int pwm2,unsigned int pwm3);
void vary_out();
void vary_frq(int rnd_up);

int i=0;
int sector=1;
float T1;
float T2;
float T0;
float PWM1,PWM2,PWM3;
float Duty1,Duty2,Duty3,Duty4;
const Ts=1/1800 ;
unsigned int x,y;
unsigned int temp;
unsigned int curr;
float K;
double ad_in;
int rnd_up;
int sec_inc;

void interrupt()
{
if(INTCON.T0IF){
INTCON.TMR0IF=0; //clear tmr0 interrupt flag bit
i=i+sec_inc; //theta=theta+1;

TMR0L=82;
TMR0H=82>>8;
}
if(PIR3.PTIF){
PIR3.PTIF=0;
PTPERH=1389>>8; //storing the value 1389 in PTPER
PTPERL=1389; // which generates a PWM signal of 1.8 KHz

}
}

void sectors (int sector )
{
switch(sector)
{
case 1: duty(duty1,duty2,duty3) ;break;
case 2: duty(duty4,duty1,duty3) ;break;
case 3: duty(duty3,duty1,duty2) ;break;
case 4: duty(duty3,duty4,duty1) ;break;
case 5: duty(duty2,duty3,duty1) ;break;
case 6: duty(duty1,duty3,duty4) ;break;
}
}

void duty(unsigned int pwm1,unsigned int pwm2,unsigned int pwm3)
{
PDC0H=pwm1>>6 ;// Stores the most significant bit of 75 in PDC0H
PDC0L=pwm1<<2; // stores the least significant bits of 75 in PDC0L and adds two more

PDC1H=pwm2>>6 ;
PDC1L=pwm2<<2;
// bits to the right to enter the first clock cycle, 75% Duty Cycle
PDC2H=pwm3>>6;
PDC2L=pwm3<<2;

PDC3H=pwm1>>6;
PDC3L=pwm1<<2;
}

void vary_out()
{

y=Adc_Read(0); //taking analog input of Vout
x=Adc_Read(1); // taking analog iput of freq control
temp=Adc_Read(2); //taking analog value of temperature sensor
curr=Adc_Read(3); //taking analog value of current sensor


ADCON0.GO=1; //starts the A/D conversion
K=y ;

rnd_up=(x/255.75) ; // to take a value from 0-4
rnd_up=ceil(ad_in); // rounding up to the next whole number


vol=K*0.0212;
//vol=(K*sqrt(3)* 25)/(1023*2); //concerting to the real voltage value
Voltage(vol);
vary_frq(rnd_up);
}

void vary_frq(int rnd_up)
{

// switch(rnd_up)
// {
// case 0:sec_inc=8 ;break;
// case 1:sec_inc=12 ;break;
// case 2:sec_inc=16 ;break;
// case 3:sec_inc=18 ;break;
// }

if(rnd_up==1)
{
sec_inc=8;
Frequency(35);
}
else if(rnd_up==2)
{
sec_inc=12;
Frequency(50) ;
}
else if(rnd_up==3)
{
sec_inc=16;
Frequency(65);
}
else if(rnd_up==4)
{
sec_inc=18;
Frequency(80) ;
}
}

void Voltage(int vol){
Lcd_Out(2, 1,"V=");
ByteToStr(vol, volt);
Lcd_Out_Cp(volt);
Lcd_Out_Cp("V");
Lcd_Out_Cp(" ");

}

void Frequency(int freq){
Lcd_Out(2,10,"F=");
ByteToStr(freq, freqncy);
Lcd_Out_Cp(freqncy);
Lcd_Out_Cp("Hz");

}

void over_current()
{
if(curr>204.6)
{


Lcd_Cmd(Lcd_CLEAR); // Clear display
Lcd_Cmd(LCD_CURSOR_OFF); // Turn cursor off
Lcd_Out(1, 1, "OVER CURRENT");

PORTD.RD0=1;
}

}

void Temperature(int temp){
if(temp > 700) {

PTCON1.PTEN=0; // stops the generation of signals

Lcd_Cmd(Lcd_CLEAR); // Clear display
Lcd_Cmd(Lcd_CURSOR_OFF); // Turn cursor off
Lcd_Out(1, 1, "OVER TEMPERATURE");

}
}
void main()
{
PDC0L=0;
PDC1L=0;
PDC2L=0;
OVDCONS=0;
QEICON=128;
PTCON1=0;
PTCON0=0;


PTCON0=2; //Postscaler 1:1, prescaler 1:1, Up/Down
PWMCON0=80; //PWM 012345 mode complementary
PWMCON1=0;
DTCON=89; //applying dead time of 5us 69 for 1us 79 for 3us 72 for 1.6us 74 for 2us
OVDCOND=63;
PTPERH=1389>>8; //storing the value 1380 in PTPER
PTPERL=1389; // which generates a PWM signal of 1.8 KHz

//for interrupts
RCON.IPEN=0; //disable priority levels on interrupts
INTCON.TMR0IF=0;
INTCON.GIEH=1;
INTCON.GIEL=1;
INTCON.TMR0IE=1;
T0CON=67; //1:16

TMR0L=82;
TMR0H=82>>8;
PTCON1.PTEN=1; // Starts the generation of signals
T0CON.TMR0ON=1; //Enables TMR0

//for A/D conversion
TRISD=0; // setting PORTD as outputs
TRISA=0xFF; //setting PORTA as inputs
ADCON0=0b00110101;
ADCON1.VCFG0=0; //VREF+ =AVDD
ADCON1.VCFG1=0; //VREF- = AVSS
ADCON1.FIFOEN=1;
ADCON2=0b00111000; //left, 16TAD, 2TOSC
ADCON3=0b11000000; //no triggers, interrupts unimplemented
ADCHS=0; //AN0, AN1, AN2, AN3 selected
ANSEL0=255;
ANSEL1=1;

TRISC = 0; // PORTC is output
Lcd_Init(&PORTC); // Initialize LCD connected to PORTC
Lcd_Cmd(Lcd_CLEAR); // Clear display
Lcd_Cmd(Lcd_CURSOR_OFF); // Turn cursor off

Lcd_Out(1, 1, "SPACE VECTOR PWM"); // Print text to LCD, 2nd row, 1st column

while (1)
{

vary_out();
Temperature(temp);
over_current();

if(i>60)
{
i=1;
sector=sector+1;
}

if(sector>6) sector=1;

T1=(K)*sinE3(60-i); // T1=T1/Ts

T1=T1/1023000;

T2=(K)*sinE3(i); // T2=T2/Ts

T2=T2/1023000;

T0=1-T1-T2; // T0=T0/Ts


Duty1=(T1+T2+(T0/2))*1389;
Duty2=(T2+(T0/2))*1389;
Duty3=(T0/2)*1389;
Duty4=(T1+(T0/2))*1389;

sectors(sector);

}


}


no delays are included. after adding the LCD part only, it deviates from proper control.... what is the reason for that??
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top