swapan
Full Member level 4
- Joined
- Feb 20, 2009
- Messages
- 204
- Helped
- 27
- Reputation
- 54
- Reaction score
- 24
- Trophy points
- 1,298
- Location
- Kolkata
- Activity points
- 2,839
Hi,
I am presently doing some practical test of peripheral of PIC 12F675. While trying to use analogue comparator, a weird result is noticed. I have made a circuit with 12F675 connected as follows.
GP 0 used as ADC as well as CIN- for comparator.
GP 1 used as output for LED_1
GP 2 used as output for LED_2
GP 3 not used.
GP 4 not used.
GP 5 used as output for LED_3.
Vdd i.e. +5v is applied to GP 0 for ADC through 10K pot.
I want to just see if ADC as well as comparator function is done by PIC simultaneously.
When ADC supply is varied though pot, LED_2 and LED_3 works as usual. But LED_1 connected to GP 1 does not work. I have scrutinized the code as well as hardware, but found no fault. At last I deactivated the comparator peripheral. Now all the LEDs work well.
Since I have utilized internal reference and GP 0 multiplexed to comparator INV input the GP1 should work as Digital IO. But it is not working when comparator function is activated.
Please see my code and suggest.
I am presently doing some practical test of peripheral of PIC 12F675. While trying to use analogue comparator, a weird result is noticed. I have made a circuit with 12F675 connected as follows.
GP 0 used as ADC as well as CIN- for comparator.
GP 1 used as output for LED_1
GP 2 used as output for LED_2
GP 3 not used.
GP 4 not used.
GP 5 used as output for LED_3.
Vdd i.e. +5v is applied to GP 0 for ADC through 10K pot.
I want to just see if ADC as well as comparator function is done by PIC simultaneously.
When ADC supply is varied though pot, LED_2 and LED_3 works as usual. But LED_1 connected to GP 1 does not work. I have scrutinized the code as well as hardware, but found no fault. At last I deactivated the comparator peripheral. Now all the LEDs work well.
Since I have utilized internal reference and GP 0 multiplexed to comparator INV input the GP1 should work as Digital IO. But it is not working when comparator function is activated.
Please see my code and suggest.
Code:
sbit LED_1 at GP1_bit;
sbit LED_2 at GP2_bit;
sbit LED_3 at GP5_bit;
unsigned int AD_Average;
void Init(void){
GPIO = 0x0;
TRISIO = 0b00001001;
ANSEL = 0x51; // TAD = 16Tosc
CMCON = 0x1E; // Analogue comparator used with internal ref.
VRCON = 0xA1; // Reference set in lowest value.
}
void main() {
Init();
while(1)
{
Delay_ms(500);
ADC_Read(0);
if (AD_Average < 250) {
LED_1 = 0;
LED_2 = 0;
}
else if (AD_Average < 420) {
LED_1 = 0;
LED_2 = 1;
}
else if (AD_Average < 650){
LED_1 = 1;
LED_2= 0;
}
else {
LED_1 = 1;
LED_2 = 1;
}
}
}