flying_yeti
Joined: 24 Jul 2011 Posts: 1
|
Problem with more than one AD Channels PIC16f876a |
Posted: Sun Jul 24, 2011 3:45 pm |
|
|
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) |
|
|