Temperature

Thread Starter

FroceMaster

Joined Jan 28, 2012
702
There are dozens of tutorials on the internet of how to read an analog value from a pic. All it takes is a little effort on your part to do some searching.

Here is just one:

http://www.ermicro.com/blog/?p=660
Have tried to copy the posted link and no matter what i get same result while compiling
Error [192] C:\***********\test.c; 53.1 undefined identifier "GODONE"

Cant see how to make it workable.
 

t06afre

Joined May 11, 2009
5,934
Rich (BB code):
// Register: ADCON0
volatile unsigned char           ADCON0              @ 0x01F;
// bit and bitfield definitions
volatile bit ADON                @ ((unsigned)&ADCON0*8)+0;
volatile bit GO_nDONE            @ ((unsigned)&ADCON0*8)+1;
volatile bit VCFG                @ ((unsigned)&ADCON0*8)+6;
volatile bit ADFM                @ ((unsigned)&ADCON0*8)+7;
volatile bit GO                  @ ((unsigned)&ADCON0*8)+1;
volatile bit CHS0                @ ((unsigned)&ADCON0*8)+2;
volatile bit CHS1                @ ((unsigned)&ADCON0*8)+3;
volatile bit CHS2                @ ((unsigned)&ADCON0*8)+4;
volatile bit CHS3                @ ((unsigned)&ADCON0*8)+5;
volatile bit nDONE               @ ((unsigned)&ADCON0*8)+1;
volatile bit GO_DONE             @ ((unsigned)&ADCON0*8)+1;
The GODONE is no doubt bit 1 in the ADCON0 register. This is from the PIC16f690 header file(Hi-Tech C V_9.83). As you can see this bit has many names. GO_DONE and GO to mention some. Use the one you like best
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
702
Works, but get many other errors.
259.11 only lvalues may be assigned to or modified
259.11 illegal conversion of integer to pointer
264.1 expression syntax

Why cant just read out the value from the input pin, ?
ex readout 0 to 1024
why all thsi delay ****, ect....
Why not just
X=AN0
temperture = X/something.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
702
Oh that is not a problem at all. But then you must write a function that do all the hard work for you:D. And that is not so hard. I have feeling the datasheet is confusing you at the current moment :p
Yes confusing with the datasheet, and frustration to get it to compile a simpel program, just get errors when i copy a sample from the internet.
 

spinnaker

Joined Oct 29, 2009
7,830
Yes confusing with the datasheet, and frustration to get it to compile a simpel program, just get errors when i copy a sample from the internet.
This hobby is more than just copying something. That is fine to learn but you need to understand what is going on too.

Folks here can help you to understand but if all you want to do is to copy something then you are in the wrong hobby.

The best thing to do is to take that very large program and write it yourself. Do not copy it just use it for ideas. Break it up into small pieces, get that to work then move on.
 

t06afre

Joined May 11, 2009
5,934
Do you still use the low pin count demo board, with a LCD connected as I once draw it up? This board has a pot connected to RA0. Let us use this pot to simulate the temprature sensor. Let us take it from the top of this list. Just plain and simple no intterrupts
9.2.6 A/D CONVERSION PROCEDURE
This is an example procedure for using the ADC to
perform an Analog-to-Digital conversion:
1. Configure Port:
• Disable pin output driver (See TRIS register)
• Configure pin as analog
2. Configure the ADC module:
• Select ADC conversion clock
• Configure voltage reference
• Select ADC input channel
• Select result format
• Turn on ADC module
3. Configure ADC interrupt (optional):
• Clear ADC interrupt flag
• Enable ADC interrupt
• Enable peripheral interrupt

• Enable global interrupt

4. Wait the required acquisition time
5. Start conversion by setting the GO/DONE bit.
6. Wait for ADC conversion to complete by one of
the following:
• Polling the GO/DONE bit
• Waiting for the ADC interrupt (interrupts enabled)
7. Read ADC Result

8. Clear the ADC interrupt flag (required if interrupt
is enabled).
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
702
Do you still use the low pin count demo board, with a LCD connected as I once draw it up? This board has a pot connected to RA0. Let us use this pot to simulate the temprature sensor. Let us take it from the top of this list. Just plain and simple no intterrupts
_Yes still use the layout / board.
That's a no go to use the pot, using it for contrast to LCD.,
Connected a sensor directly to RA0.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
702
Do you still use the low pin count demo board, with a LCD connected as I once draw it up? This board has a pot connected to RA0. Let us use this pot to simulate the temprature sensor. Let us take it from the top of this list. Just plain and simple no intterrupts

Rich (BB code):
TRISA = 0x03;
TRISA2=1;
ANSEL = 0b00000001;  // Set PORT AN0 to analog input AN1 to AN7 digital I/O
ANSELH = 0; 
ADCON0=0b10000000;   // select right justify result. ADC port channel 0
ADCON1=0b01010000;   // Select the FRC for 4 Mhz
ADON=1;
 

spinnaker

Joined Oct 29, 2009
7,830
Rich (BB code):
TRISA = 0x03;
TRISA2=1;
ANSEL = 0b00000001;  // Set PORT AN0 to analog input AN1 to AN7 digital I/O
ANSELH = 0; 
ADCON0=0b10000000;   // select right justify result. ADC port channel 0
ADCON1=0b01010000;   // Select the FRC for 4 Mhz
ADON=1;

What is your question?????
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
702
What is your question?????
sorry, was the answers to ( or beginning of )

9.2.6 A/D CONVERSION PROCEDURE
This is an example procedure for using the ADC to
perform an Analog-to-Digital conversion:
1. Configure Port:
• Disable pin output driver (See TRIS register)
• Configure pin as analog
2. Configure the ADC module:
• Select ADC conversion clock
• Configure voltage reference
• Select ADC input channel
• Select result format
• Turn on ADC module
3. Configure ADC interrupt (optional):
• Clear ADC interrupt flag
• Enable ADC interrupt
• Enable peripheral interrupt

• Enable global interrupt

4. Wait the required acquisition time
5. Start conversion by setting the GO/DONE bit.
6. Wait for ADC conversion to complete by one of
the following:
• Polling the GO/DONE bit
• Waiting for the ADC interrupt (interrupts enabled)

7. Read ADC Result

8. Clear the ADC interrupt flag (required if interrupt

is enabled).
 

spinnaker

Joined Oct 29, 2009
7,830
sorry, was the answers to ( or beginning of )

9.2.6 A/D CONVERSION PROCEDURE
This is an example procedure for using the ADC to
perform an Analog-to-Digital conversion:
1. Configure Port:
• Disable pin output driver (See TRIS register)
• Configure pin as analog
2. Configure the ADC module:
• Select ADC conversion clock
• Configure voltage reference
• Select ADC input channel
• Select result format
• Turn on ADC module
3. Configure ADC interrupt (optional):
• Clear ADC interrupt flag
• Enable ADC interrupt
• Enable peripheral interrupt

• Enable global interrupt

4. Wait the required acquisition time
5. Start conversion by setting the GO/DONE bit.
6. Wait for ADC conversion to complete by one of
the following:
• Polling the GO/DONE bit
• Waiting for the ADC interrupt (interrupts enabled)

7. Read ADC Result

8. Clear the ADC interrupt flag (required if interrupt

is enabled).

Still confused. I think you need to put a little more effort into what you are trying to say other than these one line sentences.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
702
t06afre wrote
Do you still use the low pin count demo board, with a LCD connected as I once draw it up? This board has a pot connected to RA0. Let us use this pot to simulate the temprature sensor. Let us take it from the top of this list. Just plain and simple no intterrupts
Quote:
9.2.6 A/D CONVERSION PROCEDURE
This is an example procedure for using the ADC to
perform an Analog-to-Digital conversion:
1. Configure Port:
• Disable pin output driver (See TRIS register)
• Configure pin as analog
2. Configure the ADC module:
• Select ADC conversion clock
• Configure voltage reference
• Select ADC input channel
• Select result format
• Turn on ADC module
3. Configure ADC interrupt (optional):
• Clear ADC interrupt flag
• Enable ADC interrupt
• Enable peripheral interrupt

• Enable global interrupt

4. Wait the required acquisition time
5. Start conversion by setting the GO/DONE bit.
6. Wait for ADC conversion to complete by one of
the following:
• Polling the GO/DONE bit
• Waiting for the ADC interrupt (interrupts enabled)
7. Read ADC Result

8. Clear the ADC interrupt flag (required if interrupt
is enabled).

I then wrote the answers to the first lines, i think.
Then i need to go further.
No need for interrupt, course i will just have to read the analog pin once every 3-5 seconds.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
702
This i how it should work, but will not :(
Have the
Rich (BB code):
TMR1H=0x80;
 TMR1L=0;
 //T1CON=0b00000110;//used during debug
    T1CON=0b00001110;ADCON0=0b10000000;   // select right justify result. ADC port channel 0
  ADCON1=0b01010000;   // Select the FRC for 4 Mhz
Rich (BB code):
void vis_temp (void) // Viser temperaturen
{
unsigned int degree;
char grader[4];
ADON=1;
lcd_clear();
for(;;) 
GO_DONE=1; // initiate conversion on the channel 0 
while(GO_DONE) continue;
degree = ADRESL; // Get the 8 bit LSB result
degree += (ADRESH << 8); // Get the 2 bit MSB result
lcd_goto(0x00);
lcd_puts(" Ude Temp : ");
utoa(grader, degree, 10);
lcd_puts(grader);
}
Just an empty LCD ;(
 

spinnaker

Joined Oct 29, 2009
7,830
You need to start simple.

First just get the LCD to display something.

Write a program that prints Hello World! to the LCD.

Forget about the ADC for now.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
702
You need to start simple.

First just get the LCD to display something.

Write a program that prints Hello World! to the LCD.

Forget about the ADC for now.
If you have read from beginning, you would see that i allready have LCD to function.
i can get i to write everything, but when it comes to the part where it should read the analog input, the program hangs up.

in this part of code it stops
Rich (BB code):
for(;;) 
GO_DONE=1; // initiate conversion on the channel 0 
while(GO_DONE) continue;
degree = ADRESL; // Get the 8 bit LSB result
degree += (ADRESH << 8); // Get the 2 bit MSB result
lcd_goto(0x00);
lcd_puts(" Ude Temp : ");
utoa(grader, degree, 10);
lcd_puts(grader);
it seems that the Go_done, / while statement is hanging up
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
702
Are you sure it's not the

Rich (BB code):
for(;;)
that's mess things up?
Could be. Just somewhere in that statement
Not that familier with "for" statement in c code

Removed the "for" line. Then it works
now i need to get the right degree. But that should be simple
 
Last edited:
Top