I'm guessing that you have 5V as Vref and so to get the maximum ADC value with only 3.5V in you need to multiply the ADC value by 5/3.5 (woops, got that wrong way around above).
Try,
Code:
Dim temp as word
main:
ADCON1.7 = 0 'left justify
ADCON0.2 = 1 'start A/D conversion
while(ADCON0.2=1) 'wait for it to complete
wend
temp=adresh
temp=temp*10 '2*5
temp=temp/7 '2*3.5 = adresh*5/3.5
output1 = temp / 32
WaitMs 100
Goto main
hi Mike,
If the OP is using picsim ide Basic [oshonsoft???] then if he:
DIM output1 as BYTE then the Basic sets ADC as left justify, 8 bit only.
DIM output1 as WORD its right justified full 10 bit.
Looking at your diagram, the voltmeter should not go from the potentiometer to the input pin. Remove the voltmeter and connect the potentiometer slider to the pic pin. If you want to see the voltage then connect a voltmeter from the slider/pic pin to ground.
Looking at your diagram, the voltmeter should not go from the potentiometer to the input pin. Remove the voltmeter and connect the potentiometer slider to the pic pin. If you want to see the voltage then connect a voltmeter from the slider/pic pin to ground.
That code is doing temp=temp/0.7 (or temp=temp*1.44) but as we are using integer maths the way we do it is to multiply by 10 and then divide by 7. Now your diagram is corrected you wont need this part.
That code is doing temp=temp/0.7 (or temp=temp*1.44) but as we are using integer maths the way we do it is to multiply by 10 and then divide by 7. Now your diagram is corrected you wont need this part.
i see, but how do you come up 0.7 to divide it? btw, what do you mean by 'you wont need this part' coz when i omitted the line the output is not the same. since it was program for 3bits which is divided by 32, meaning to say i can divide it with 16 to obtain 4bits of output?
btw, is there a thread here regarding on how to use the timer module of 877 using basic? 'coz i would like to try using its timer by this simple operation:
1. start timer running
2. wait for input (e.g RA0 = 1)
3. store the value of the timer when RA0 is low while continuing the time
4. store another value of the time when RA0 is pressed again
5. compare the the 2 values and compute for the difference.
or any sample program that uses timer module of 877 that uses basic will do.. i got nose bleed when reading the datasheet..