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 CCS Technical Support

Problem with more than one AD Channels PIC16f876a

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



Joined: 24 Jul 2011
Posts: 1

View user's profile Send private message

Problem with more than one AD Channels PIC16f876a
PostPosted: Sun Jul 24, 2011 3:45 pm     Reply with quote

Hello,

I got a problem with the use of more than one AD Converters. If I read only channel I can use the variable for my PWM Signal. But if I put another one into the program it doesn't work. I would be glad for any response.
Code:

#include "D:\PICC\kugel\next\next.h"
#use delay(oscillator=4000000)
#use fast_io (B)

void main()


/*#use standard_io(C)
  #use fast_io (C)
   SET_TRIS_c(0x3F); 
   */
 
long int AO,channel2, channel3,channel5;
long int A3;
long int A5;

 SET_TRIS_b(0x00);

   setup_adc_ports(ALL_ANALOG);
   setup_adc(ADC_CLOCK_DIV_8);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_16,255,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
 
   setup_ccp1(CCP_PWM);
 
output_low(PIN_C6);
output_low(PIN_C7);
output_low(PIN_B6);
output_low(PIN_B5);
output_low(PIN_B4);
output_low(PIN_B3);
output_low(PIN_B2);
output_low(PIN_B1);

channel2=0;
channel3=0;
channel5=0;
AO=0;
A3=0;
A5=0;


while(1)
{

set_adc_channel(2);
delay_us(100);
channel2=read_adc();

set_adc_channel(3);
delay_us(100);
channel3=read_adc();
delay_ms(1);

if(channel3>=512){
output_high(PIN_B3);}

delay_us(50);

     set_pwm1_duty(channel2);         
   }             
  }

And the FUSES:
Code:

#include <16F876A.h>
#device ICD=true
#device adc=10

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES XT                       
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected

#use delay(clock=4000000)
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jul 24, 2011 4:31 pm     Reply with quote

couple of notes...

Don't use the use fast_io and set_tris statements and let the compiler handle all the I/O pin details. Forcing them 'manually' can cause problems when you think a pin is an input but you've actually made it an output.

also

The variable AO appears to be the letter 'A' and the letter 'O' but similar variables are A3 and A5...it can be confusing to read after a few hours....

and..

/*#use standard_io(C)
#use fast_io (C)
SET_TRIS_c(0x3F);
*/
I'm confused as to whether this gets compiled or is commented out....bet the compiler might not like it either....
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