|
|
View previous topic :: View next topic |
Author |
Message |
uma
Joined: 17 Apr 2014 Posts: 29 Location: chennai
|
getting error in code to read AI |
Posted: Wed May 07, 2014 6:35 am |
|
|
#include <16f877a.h>
#device ADC=8
#fuses HS,NOLVP,NOWDT,PUT
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#include <lcd.c>
void main()
{
lcd_init();
delay_ms(10);
int Vin0;
while(TRUE)
{ setup_adc_ports( RA0_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
delay_ms(100);
Vin0 = read_adc();
vin0 = (vin0/32)+0x30;//to convert to ASCII
printf(lcd_putc,"input = ",Vin0);
}
}
link for error screenshot:
http://postimg.org/image/fm7c4d24r/
help me in resolving the error _________________ uma
Application Engineer,
ETPL |
|
|
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Wed May 07, 2014 6:48 am |
|
|
You haven't put a format specifier in your
Code: | printf(lcd_putc,"input = ",Vin0); |
something like
Code: | printf(lcd_putc,"input = %d",Vin0); |
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed May 07, 2014 10:27 am |
|
|
1) Add 'errors' to '#use rs232'.
2) Include a 500 - 1000 ms delay before 'lcd_init()'.
3) Use the code button to preserve format.
I can do without the 'interesting' addition to the link.
Mike |
|
|
uma
Joined: 17 Apr 2014 Posts: 29 Location: chennai
|
how to read the adc count displayed in volts & millivolt |
Posted: Fri May 09, 2014 2:00 am |
|
|
how to read the adc count displayed in volts & millivolts when i vary the pot.In my previous code iam able to read the value in count when i vary the pot.what are the changes to be made in code to read in volt or millivolt.
the count varies from 0-255.
Code: |
#include <16f877a.h>
#device ADC=8
#fuses HS,NOLVP,NOWDT,PUT
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,errors)
#include <lcd.c>
void main()
{ delay_ms(500);
lcd_init();
int Value;
while(TRUE)
{ setup_adc_ports( RA0_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
delay_ms(7);
Value = read_adc();
printf(lcd_putc,"\f%U ",Value);
}
} |
_________________ uma
Application Engineer,
ETPL |
|
|
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Fri May 09, 2014 2:23 am |
|
|
You come here and ask for help, but do not give any thanks when solutions and suggestions are provided.
How rude.. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri May 09, 2014 2:48 am |
|
|
A small comment on your program. You are setting up the ADC every loop. That is extra overhead you can avoid by moving the two setup lines to the start of main.
Calculating the voltage from the 0-255 count is very easy. Your whole project feels like a student exercise. That's OK, but we are not going to do your homework.
Even if you don't know how to do it as a program you can show us you did put in some effort by showing us the formula or whatever other ideas you have. |
|
|
uma
Joined: 17 Apr 2014 Posts: 29 Location: chennai
|
RE: |
Posted: Fri May 09, 2014 3:51 am |
|
|
Hi guys,
I wont be online always, so i can't comment anything immediately, that is reason for my slow response to you. Don't mistake me for i am not giving the result to the solutions or suggestions you people give..... _________________ uma
Application Engineer,
ETPL |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Fri May 09, 2014 4:19 am |
|
|
ADC_CLOCK_INTERNAL, is _wrong_.
It'll work, but degrade the accuracy of your ADC (may not matter as you are only using it in 8bit mode). This clock is not recommended (read the data sheet) for CPU's running above 1MHz.
For your chip, with 5v in, each step of the ADC in 8bit mode is 5/256 volts (research why 256, not 255, given there are 255 actual 'risers' - search here will find why). With the full display being reached at about 4.97v.
For reasonable resolution you want to switch to 10bit mode.
A 'close to accurate' conversion, will then be (lots of comments inline):
Code: |
#include <16f877a.h>
#device ADC=10 //using 10bit mode
#fuses HS,NOLVP,NOWDT,PUT
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,errors)
void main()
{
int32 value; //In C, variables should be declared at the start
//of code blocks. CCS 'sort of' allows mid code declarations, but they
//will cause occasional oddities. Stick to C....
delay_ms(500);
lcd_init();
setup_adc_ports( RA0_ANALOG );
setup_adc(ADC_CLOCK_DIV_16);
set_adc_channel( 0 );
//set things up _once_
while(TRUE)
{
delay_ms(200);
//Most LCD's can't update faster than perhaps 5* per second...
Value = (read_adc() * (int32)5000)/1024;
//This uses _integer_ maths (efficient and quick). No actual division.
//Done using rotation on an integer.
printf(lcd_putc,"\f%6.3LW ",Value);
//displays the value in volts.
}
}
|
Hopefully you take the time to research _why_ certain things are done, and how this can work. |
|
|
uma
Joined: 17 Apr 2014 Posts: 29 Location: chennai
|
RE:Ttelmah, got the o/p but right or not? |
Posted: Sat May 10, 2014 1:13 am |
|
|
I have done something, i don't know it is wright or wrong.
I post my code and screen shot in which i get my output in millivolts, you just have a look, is that ok or not?
Code: |
#include <16f877a.h>
#device ADC=8
#fuses HS,NOLVP,NOWDT,PUT
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,Errors)
#include <lcd.c>
void main()
{
delay_ms(500);
lcd_init();
setup_adc_ports(ALL_ANALOG);
setup_adc( ADC_CLOCK_INTERNAL );
delay_ms(20);
int Value,Value1; float mvolts,mvolts1;
while(1)
{
set_adc_channel( 0 );
delay_ms(100);
Value = read_adc();//max count value=255,min=0
mvolts = (value * 19.607);//mv=5000/255*valueupdated
printf(lcd_putc, "\f %f mv", mvolts);
set_adc_channel( 1 );
delay_ms(200);
Value1 = read_adc();//max count value=255,min=0
mvolts1 = (value1 * 19.607);//mv=5000/255*valueupdated
printf(lcd_putc, "\n %f mv", mvolts1);
}
}
|
link for screenshot:
http://s1.postimg.org/ot3kp2tcv/AI_simulated.jpg _________________ uma
Application Engineer,
ETPL |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sat May 10, 2014 5:04 am |
|
|
Are you using Proteus ? You say 'AI_simulated.jpg'.
We need to know if this is real hardware or a simulation.
There are errors in the code BUT if using Proteus , IT will cause errors as well.
hth
jay |
|
|
uma
Joined: 17 Apr 2014 Posts: 29 Location: chennai
|
RE: |
Posted: Sat May 10, 2014 5:13 am |
|
|
yes i am using proteus 8.0,and in later stage i am going to do in real hardware combining all DI,DO,AI,AO,CI,CO in a single program,for that i am learning now in simulation. Image which i post is the screenshot taken and saved in paint and posted to you in website.The name to the posted image were given by me for identification. _________________ uma
Application Engineer,
ETPL |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Sat May 10, 2014 5:36 am |
|
|
Uma,
You are hopeless. You completely blew off most of what Ttelmah directly told you was wrong. I think the forum should just start ignoring you, as clearly you are not worth the effort!!
You are just mindlessly throwing code together and then asking us to waste our time to fix it.......
Cheers,
John |
|
|
uma
Joined: 17 Apr 2014 Posts: 29 Location: chennai
|
RE:thanks to alllllllll. |
Posted: Sat May 10, 2014 5:54 am |
|
|
sorry guys as iam helpless iam comming to the forum for help,but you people say that iam wasting all your time,thre truth is you people are entertaining with my unknown knowledge of code.......
anyway thanks for alll your help.....and i say i dont worry even if you people ignore me. i have the hope sure one day i will be the best pic programmer.bye...... _________________ uma
Application Engineer,
ETPL |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sat May 10, 2014 6:22 am |
|
|
You have to understand everyone here works with REAL PICS and real hardware.
It is the ONLY way to properly learn how to use PICs.
Proteus is a very,very poor 'simulator', FULL of bugs, errors and faulty DRCs. You could not pay me to use it.
No one can truly help with that 'simulator'. Your code might be 100% correct but Proteus has internal faults which cause your program to 'not work'.
That's why I posed the question. CCS C code in a PIC is easy to debug as we can 'cut and paste', compile, download into our PICs and actually see what is happening.
I also know that not everyone can afford to buy the basic PIC hardware but if you're going to get into the 'field of microcomputers' ,save up, buy the basics and learn by doing.
Others may say Proteus is good for 'somethings' BUT if you cannot rely upon it 100%, it truly has zero value.
In the meantime, have a look at the examples CCS supplies in the 'examples' folder. They will show you some good techniques to program the PIC.
I admit I'm not a great C programmer even though I've got 20 years with PICs but a simple white breadboard and a few parts I've managed to get things to work fine. Bench time experience is worth more than playing a video game!
cheers
jay |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Sat May 10, 2014 7:47 am |
|
|
Hi Jay,
This isn't a 'Proteus issue', this is an 'uma issue'. TTelmah told him directly "ADC_CLOCK_INTERNAL, is _wrong_", and yet he still did it. Ttelmah told him about the danger of declaring variables 'inline', and yet he still did it. Ttelmah told him how to make his A/D conversion 'cleanly' without floats and complicated division, and yet he still did it. In previous uma threads we had to tell him repeatedly 'use the Code buttons', and 'add Errors to your #use rs232', and he ignored that as well until told again and again......
Again, the problem is not simulation vs. real-world, it's that uma's brain appears to be switched off. He seems content to 'learn C' by forum' and 'troubleshoot by forum', and IMHO it's a colossal waste of time.
John |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|