Well, troubles continue.
I've built a following circuitry. 10K resistor goes to LATA.2 pin and goes then to gnd.
100k variable pot is connected one end to VCC, another to LATA.2
LED is connected to GND via 1k resistor from LATA.1
Wiring is 100% checked and corrected for shorts, misswire, etc.
The code is as follows:
This code should do a simple thing - vary LED brightness according to pot setting. And sure it does, but the problem is that it works in very narrow range, because port sinks huge amount of current - up to 25mA via that pin. So say to achieve 2.5v on the pin, the pot resistance should be set somewhere to 40 ohms. I think this is not correct, right?Code:OSCCON = %11110000 'SET INTOSC TO 32MHZ TRISA=%00110000 'set PORt as input 'ANSELA=%00010101 'set PORTA.4 as analog ADCON0=%00001111 'ENABLE AND CONFIGURE ADC ADCON1=%11000011 'JUSTIFY FVRCON=%11011111 'VREF ENABLE & set at 4.096v WPUA=%00000000 'pull up disable 'CM1CON0=%00000000 'DISABLE COMPARATORS DEFINE OSC 32 DEFINE ADC_BITS 10 DEFINE ADC_SAMPLEUS 50 DEFINE ADC_CLOCK 3 VOLT VAR WORD LED VAR LATA.1 greater: adcin 2,volt high led pause 1 low led pause volt/10 goto greater
Also I found a strange thing - if I set TRISA=%00110010, which means to set LATA.2 as input, the code does not works at all, but it also stops consuming current on that pin. What can be the reason?





Bookmarks