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

CAD 3 channels

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







CAD 3 channels
PostPosted: Thu May 06, 2004 6:29 pm     Reply with quote

hi people:

I have a problem, I need use 3 channel but I can't did that. But I can used one channel, I Have pic 16f877 : but I need your help: my code is:

#if defined(__PCM__)
#include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#byte puertab=0x06

void main() { //
int value0,value1,value2;
set_tris_b(0x00);
setup_adc_ports(ALL_ANALOG);
setup_adc( ADC_CLOCK_INTERNAL );
// set_adc_channel( 1 );


do {
set_adc_channel(0);
value0 = Read_ADC();
puertab=value0;
delay_ms(500);

set_adc_channel(1);
value1 = Read_ADC();
puertab=value1;
delay_ms(500);

set_adc_channel(2);
value2 = Read_ADC();
puertab=value2;
delay_ms(500);

} while (TRUE);
}


please helpme !!

bye and thank u.
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Thu May 06, 2004 6:39 pm     Reply with quote

Two things:

1. From PIC16F877 datasheet: "When the device frequencies are greater than 1 MHz, the internal RC A/D conversion clock source is only recommended for SLEEP operation.". So for a 4MHz crystal it is recommended to use setup_adc(ADC_CLOCK_DIV_8).

2. From the CCS help file on set_adc_channel(): "Be aware that you must wait a short time after changing the channel before you can get a valid read. The time varies depending on the impedance of the input source. In general 10us is good for most applications.". You need to add that delay everytime you change the ADC channel, something like this:

Code:
do {
    set_adc_channel(0);
    delay_us(10);              //Add this delay here
    value0 = Read_ADC();
    puertab=value0;
   delay_ms(500);
...
...
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu May 06, 2004 7:11 pm     Reply with quote

Another "good" way to delay is to make a dummy read of the new channel.

Code:

#define COWS_NOT_HOME 1

while(COWS_NOT_HOME)
{
   for(i=0;i<3;i++)
   {
      set_adc_channel(i);
      value[i] = Read_ADC();
      value[i] = Read_ADC();
   }
   /* now do something wonderful with your new data */
}
 


This can possibly make your code smaller if you haven't already used the delay_us() function anywhere else.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
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