SparkyChem
Member level 3
- Joined
- Apr 22, 2010
- Messages
- 57
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Lima, Peru
- Activity points
- 2,084
Hello there, i have this mikrobasic code but my problem is that i don't know how to modify it so it can work with voltages higher than 5 volts. The uC i'm using is PIC16F676 which has an internal ADC module.
Maybe if i make Vref different than Vdd and i do tie that pin to a different reference i.e 1.25V and then using an op amp to downsize the voltage from let's say 9volts to 900mV and then using that signal from the output side of an op amp as the one which would then be measured by the ADC module. Would that be okay?. i wonder if doing that would mean losing accuracy in the adc conversion process.
i'm sorry i don't know what to do. Any help would be appreciated, thanks in advance.
Maybe if i make Vref different than Vdd and i do tie that pin to a different reference i.e 1.25V and then using an op amp to downsize the voltage from let's say 9volts to 900mV and then using that signal from the output side of an op amp as the one which would then be measured by the ADC module. Would that be okay?. i wonder if doing that would mean losing accuracy in the adc conversion process.
i'm sorry i don't know what to do. Any help would be appreciated, thanks in advance.
Code:
program F676_exp
' Declarations section
'******************************************************
dim LCD_RS as sbit at RC4_bit ' Lcd
LCD_EN as sbit at RC5_bit
LCD_D4 as sbit at RC3_bit
LCD_D5 as sbit at RC2_bit
LCD_D6 as sbit at RC1_bit
LCD_D7 as sbit at RC0_bit
LCD_RS_Direction as sbit at TRISC4_bit
LCD_EN_Direction as sbit at TRISC5_bit
LCD_D4_Direction as sbit at TRISC3_bit
LCD_D5_Direction as sbit at TRISC2_bit
LCD_D6_Direction as sbit at TRISC1_bit
LCD_D7_Direction as sbit at TRISC0_bit ' LCD
dim text as string [16] ' text string
dim ch, adc_rd as word ' ch, adc_rd word
dim tlong as word ' tlong, longword
sub procedure settings
CMCON=7
ANSEL=%00000001
ADCON1=%00110000
ADCON0=%10000001
TRISA=%000001
INTCON = 0 ' all interrupts disabled
TRISC = 0 ' PORTC is output
end sub
main:
' Main program
settings
Lcd_Init() ' LCD
Lcd_Cmd(_LCD_CURSOR_OFF) ' LCD (off)
Lcd_Cmd(_LCD_CLEAR) ' LCD command (clear LCD)
text = "mikroElektronika" ' First message
Lcd_Out(1,1,text) ' First message, first line
text = "LCD example" ' Second message
Lcd_Out(2,1,text) ' Second message, second line
Delay_ms(500)
text = "Voltage=" ' Third message
while 1 ' Loop
adc_rd = ADC_Read(0) ' A/D conversion. RA0 input.
Lcd_Out(2,1,text) ' Result second line
tlong = adc_rd * 5000 ' Milivolt
tlong = tlong / 1023 ' 0..1023 -> 0-5000mV
ch = (tlong / 1000) mod 10 '
'
Lcd_Chr(2,9,48+ch) '
Lcd_Chr_CP(".") '
ch = (tlong / 100) mod 10 '
Lcd_Chr_CP(48+ch) '
ch = (tlong / 10) mod 10 '
Lcd_Chr_CP(48+ch) '
ch = tlong mod 10 '
Lcd_Chr_CP(48+ch) '
Lcd_Chr_CP("V") ' Show "V"
Delay_ms(1) ' 1mS delay
wend
end.