kodi.sudar
Member level 5
- Joined
- Dec 21, 2009
- Messages
- 92
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- india
- Activity points
- 1,849
Code:
if ((adc_val>=0x0000022B) && (adc_val<0x0000024D))
{
PWMMR2 = 0x0000004C;
PWMMR4 = 0x0000004A;
PWMLER = 0x0000014;
Code:
if ((angle >= 7.996409) && (angle < 18.20971))
{
PWMMR2 = 0x0000004C;
PWMMR4 = 0x0000004A;
PWMLER = 0x0000014;
}
Thanks alexI have already replied in the same question yesterday.
What I can add is make the variables global volatile and use breakpoints in proteus to review the values and check if they are correct.
in keil i have the access to variables in watch window. But to display that i am looking . i tried with sprint f but it didn't workone way is to mupliply it so that it becomes an integer and convert it to ASCII characters with a custom function
Another way is to use sprintf()
In order to debug in proteus you don't need to show the value in a display, you have access to all variable values in the watch window
#include <stdio.h>
char buffer [21]; // Set size to LCD width plus one null
sprintf (buffer, "ADC Value: %X", adc_val);
lcd_puts(buffer);
float my_float=1.2345;
char buffer [21]; // Set size to LCD width plus one null
int main(void)
{
....
sprintf (buffer, "ADC Value: %f", my_float);
...
}
I don't see a problem, this works fine
Code:float my_float=1.2345; char buffer [21]; // Set size to LCD width plus one null int main(void) { .... sprintf (buffer, "ADC Value: %f", my_float); ... }
When I check the content of the array in the debugger after the sprintf line it contains the converted float.
I assume there is a problem with the LCD function.
You have included <stdio.h> right?
#include <LPC21xx.H>
#include <stdio.h>
void delay( )
{
unsigned int i;
for(i=0;i<4000;i++);
}
void lcddata(unsigned char c)
{
IOCLR1=0x00ff0000; // output p1.16 to p1.24
IOSET0=0x00000001; // rs =1 p0.0
IOCLR0=0x00000002; // rw =0 p0.1
IOSET0=0x00000004; // en=1 p0.2
IOSET1 = c<<16;
delay();
IOCLR0=0x00000004; //en=0 p0.2
}
void lcdcmd(int c)
{
IOCLR1=0x00ff0000;
IOCLR0=0x00000001; // rs =0 p0.0
IOCLR0=0x00000002; // rw =0 p0.1
IOSET0=0x00000004; // en=1 p0.2
IOSET1 = c<<16;
delay();
IOCLR0=0x00000004; //en=0 p0.2
}
void lcdinit()
{
lcdcmd(0x38);
delay();
lcdcmd(0x0e);
delay();
lcdcmd(0x06);
delay();
lcdcmd(0x80);
delay();
}
void lcdputs(const char * s)
{
while(*s)
lcddata(*s++);
}
sprintf (buffer, "ADC Value: %f", my_float);
float my_float=1.2345;
i tried even like that but same problem lcd just turns on . on other change in that .What happens if you use a predefined float value like I did and not the calculated one?
For example
Code:float my_float=1.2345;
i tried even like that but same problem lcd just turns on . on other change in that .What happens if you use a predefined float value like I did and not the calculated one?
For example
Code:float my_float=1.2345;
char buffer [21]= "ADC Value: 1.2345"
lcd goes blankWhat happens if you use
Code:char buffer [21]= "ADC Value: 1.2345"
And try to show it using lcdputs?
char buffer [16]= "ADC Val: 1.2345"
Ya it prints the value now.Then it is clear that sprintf is not the problem, there is something wrong with the LCD function.
Maybe the problem is the array length?
Do you use 16x2 LCD?
Does it print:
Code:char buffer [16]= "ADC Val: 1.2345"
Limit the length of the string to 16 characters, check the %f parameter to round the value in less digits (like %0.4f) and make sure that the total is not more than 16 char
Show me what you have done
#include <LPC213X.H>
#include <stdio.h>
#include <math.h>
#include "lcdx.h"
//char buffer [16]= "ADC Val: 1.2345";
//VBC CLOCK 12MHZ
void delay();
void adc_datax();
void adc_inix();
void adc_datay();
void adc_iniy();
unsigned long val,adc_val,val1,adc_val1;
unsigned char buffer [16]; // Set size to LCD width plus one null
float y,s,v,m;
float angle,b;
int main(void)
{
while(1)
{
adc_inix(); //initializing adc
adc_datax();//extracting data
/*code for lcd print*/
//PINSEL0=0X00000000; // gpio pin 0.0 to 0.15
// PINSEL2=0X00000000; // gpio pin 1.16 to 1.31
IODIR0=0X00000007; //p0.0 rs p0.1 r/w p0.2 e
IODIR1=0X00ff0000; //p1.16 to p1.24 output
lcdinitx();
m=(3.3/1023);/*3.3/1023 for adc conversion*/
y=1.65;/*offset voltage */
s=0.8;/*sensitivity 800mv/g*/
b=57.295;/* pi/180 for radian to degree conversion */
/* formula tetha= arcsin( (vout - voffset)/sensitivity) */
v=asin(((adc_val*m)-y)/s);
angle=v*b;
sprintf (buffer, " adc %0.4f", angle);
lcdputs(buffer);
}
void adc_inix(void)
{
// PINSEL = 0X05000000; //pin 13,14 p0.28,0.29 adc 0 channel 1 &2
PCONP |= 0X00001000; //select adc 0 bit 12
AD0CR &= 0X00000000;
AD0CR |= 0X00200206; // WITH PCLK 12/(2+1)=4MHZ ADC0 and 1 CHANNEL 1 PIN 13
AD0INTEN &= 0x00000000; //Completion of a conversion on ADC channel 0 will not generate an interrupt.
}
void adc_datax(void)
{
AD0CR |= 0x01000000; /* Start A/D Conversion */
while((AD0DR & 0x80000000)==0); //until bit 31 is high (DONE)
val = AD0DR; //read a/d data register
adc_val = ((val >> 6) & 0x3FF); // Extract AD result
}
unsigned char buffer [16]; // Set size to LCD width plus one null
[COLOR="#FF0000"]angle= 123.4567; [/COLOR] // add this before sprintf to see if you get output
sprintf (buffer, " adc %0.4f", angle);
lcdputs(buffer);
To do that you need 16 char + null so the length should be buffer [17] but this shouldn't be a problem.
Move the initialization out of the while loop, why is it still inside the while loop?
You are also printing the lcd several timer per second and I'm not sure it this causes your problem.
What is the value of angle when you reach sprintf, maybe that is the problem.
What if you try without changing anything else
Code:[COLOR="#FF0000"]angle= 123.4567; [/COLOR] // add this before sprintf to see if you get output sprintf (buffer, " adc %0.4f", angle); lcdputs(buffer);
angle= 123.4567;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?