M.Rehan
Full Member level 2
VOLTAGE_FACTOR not showing proper value
when V is greater than 512
MIKROC Pro For PIC
PIC 18F46k22
- - - Updated - - -
Formula for Voltage factor is
where voltage factor is 1.00 initially
- - - Updated - - -
I know it is problem with floating point mathematics
Something is missing doing maths in MikroC compiler
when V is greater than 512
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 sbit LCD_RS at RD4_bit; sbit LCD_EN at RC7_bit; sbit LCD_D4 at RC6_bit; sbit LCD_D5 at RC5_bit; sbit LCD_D6 at RC4_bit; sbit LCD_D7 at RD3_bit; sbit LCD_RS_Direction at TRISD4_bit; sbit LCD_EN_Direction at TRISC7_bit; sbit LCD_D4_Direction at TRISC6_bit; sbit LCD_D5_Direction at TRISC5_bit; sbit LCD_D6_Direction at TRISC4_bit; sbit LCD_D7_Direction at TRISD3_bit; char V_TEXT[8]; char FACTOR_TEXT[11]; char TEMP_TEXT[11]; float VOLTAGE_FACTOR = 1.00; float TEMP_FACTOR_1 = 0; float TEMP_FACTOR = 0; unsigned int V = 0; void main() { TRISA = 0x2F; PORTA = 0x00; LATA = 0x00; ANSELA = 0x2F; TRISB = 0xFF; PORTB = 0x00; LATB = 0x00; ANSELB = 0x00; TRISC = 0x00; PORTC = 0x00; LATC = 0x00; ANSELC = 0x00; TRISD = 0x00; PORTD = 0x00; LATD = 0x00; ANSELD = 0x00; Lcd_Init(); Lcd_Cmd(_LCD_CLEAR); Lcd_Cmd(_LCD_CURSOR_OFF); while(1) { Delay_ms(1000); V = ADC_Read(3); TEMP_FACTOR_1 = 512-V; TEMP_FACTOR_1 = TEMP_FACTOR_1/512; VOLTAGE_FACTOR = TEMP_FACTOR_1 + VOLTAGE_FACTOR; Delay_ms(100); IntToStr(V,V_TEXT); lcd_out(1,1,V_TEXT ); Delay_ms(100); floatToStr(VOLTAGE_FACTOR,FACTOR_TEXT); lcd_out(2,1,FACTOR_TEXT ); Delay_ms(100); } }
MIKROC Pro For PIC
PIC 18F46k22
- - - Updated - - -
Formula for Voltage factor is
Code:
Voltage Factor = ((512-V)/512) + Voltage Factor
where voltage factor is 1.00 initially
- - - Updated - - -
I know it is problem with floating point mathematics
Something is missing doing maths in MikroC compiler