CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

how can i tell this if this is working?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hoss`



Joined: 16 Mar 2005
Posts: 3

View user's profile Send private message

how can i tell this if this is working?
PostPosted: Wed Mar 16, 2005 2:15 pm     Reply with quote

I'm kind of a noob when it comes to programming the pic and I was hoping for some help with a few simple questiosn...

here's what i'm trying to do. I'm using an LM34 temperature sensor and all I want to do is get the digital voltage to be able to eventually output serially. What I've done so far is follow the application note of the LM34 and output both the value of LM34 and a reference voltage of 2.55v to the PIC.

Here's the code I've got so far....

Code:

#include <16F874.H>

#use delay(clock=20000000)

void main()
{

   double temp_in = 0;
   double temp = 0;
   int i;

   // Setting up Port A to do ADC on Pin 2
   setup_port_a(ALL_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0);


   // Allowing a delay to make sure the ADC
   // works properly
   delay_ms(100);   
   
   while(1)
   {
      for (i = 0; i < 19; i++)
      {
         temp_in = temp_in + read_adc();
         delay_ms(50);
      }
   
      temp = temp_in / 20;
   }   
}


Info about what I'm using: PIC 16f874, compiler: CCS C compiler

I'm not quite sure how the ADC really works. From what I understand it'll compare the voltage with 2.55v (my reference voltage) / 255 (8bit adc) = 0.01 = 10mV. 10mV output from the LM34 = 1 degree. I read an application where someone used that and it seems to make sense to me.

What I want to do is be able to see what kind of value I will be outputting. Is there a way to do a printf and see what value I'm getting? Also am I using the ADC correctly or no?

As you can see I'm really unsure of what I'm doing so any help will be much appreciated. Thanks in advance! Very Happy
Ttelmah
Guest







PostPosted: Wed Mar 16, 2005 3:39 pm     Reply with quote

You talk about your reference voltage. What pin is it connected to?. You need to tell the ADC to use the reference voltage. The key is a table in the chip data sheet, entitled 'register 11-2', 'ADCON1 register'. The instruction 'setup_port_A', actually sets this register. If you look at the tble, the top line showing all the pins used as analog, has Vref, coming from the chip supply voltage, not the external pins. The setting 'ANALOG_RA3_REF', instead selects Vref to be on RA3, and the rest of portA to be used as analog inputs. To use a 2.55v reference, you will need to use this setting (or one of the others with less analog pins enabled).
Yes, you can do a printf. You need to add a #use RS232 statement (there are dozens of examples in the examples directory of this), and connect the output pin, via a MAX232 or similar RS232 transceiver to the serial input pin of a PC (and the 0V connections between the two units as well). Then you can just add a printf to see what is in your temp register.
Since you are adding 20 readings, then looping, the statement to zero the temp_in register should be moved to the line in front of the 'for' statement, or the contents will keep growing, and quickly overflow the storage.
You should change your type definitions to 'int16'. Double is not a supported type, unless you have defined it for yourself.

Best Wishes
hoss`



Joined: 16 Mar 2005
Posts: 3

View user's profile Send private message

PostPosted: Mon Mar 21, 2005 10:38 am     Reply with quote

okay here's an updated version of my code...

Code:

#include <16F874.H>

#use delay(clock=20000000)
#use rs232(DEBUGGER)

void main()
{

   int16 temp_in = 0;
   int16 temp = 0;
   int i;

   // Setting up Port A to do ADC on Pin 2
   setup_port_a(ANALOG_RA3_REF);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0);


   // Allowing a delay to make sure the ADC
   // works properly
   delay_ms(100);   
   
   while(1)
   {
      temp_in = 0;

      for (i = 0; i < 19; i++)
      {
         temp_in = temp_in + read_adc();
         delay_ms(50);
      }
   
      temp = temp_in / 20;
   }   
}


I still need help reading the output. I'm using the ICD-S and MPLAB IDE program. Is there a way to just test the output using a printf? If so how can I get it to show the ouput through the program? Thanks.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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