Is this the way to get negative reading? i am new to this, so sorry if i mixed it up.
I use Allegro ACS714 but with a PIF16F690 with A/D set to 8bit, should not be any difference.
It works and can read +30Amp to -30Amp.
The problem is that i use 0V and 5V as reference. I cant figure out to get 0.52V to read 0 and 4.48V to read 255? Is it a math problem or must i add an external ref?
The ACS gives 66mV/A:
Amp Vin Bit
+30A 4.480 255
+10A 3.160
+1A 2.566
0A 2.500 127
-1A 2,434
-10A 1.840
-30A 0.520 0
See CODE below and attached DRAWING
Code:'Define OSC and ADC DEFINE OSC 4 ' Set internal Oschillator to 4Mhz DEFINE ADC_BITS 8 ' Set number of bits in result DEFINE ADC_CLOCK 2 ' Set clock source (3=rc) DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS ' Define LCD pins Define LCD_DREG PORTC 'LCD data port Define LCD_DBIT 0 'LCD data starting bit 0 or 4 Define LCD_RSREG PORTC 'LCD register select port Define LCD_RSBIT 4 'LCD register select bit Define LCD_EREG PORTC 'LCD enable port Define LCD_EBIT 5 'LCD enable bit TRISA = %00001001 ' RA0 = A/D input ADCON1.7 = 0 ' RA.1 = +Vref, Set PORTA analog and left justify result PORTb.6 =0 ' Prepare RB0 for high-going pulseout ANSEL = %00000101 ' Set PORTA.2 analog, rest digital ANSELH = %00000000 ' Variables outpuls VAR WORD ' Variable for the calculated puls out in mS POT_POS VAR BYTE ' Potentiometer position CC=0, CCW=255 amp var word ' Ampere 30A-0-30A (0-127-255) Pause 500 ' Wait for LCD to start MainLoop: ' The Loop start here! ADCIN 0,POT_POS ' Read A/D channel 0 to variable SVO_POS 'Check if negative or positive Ampere IF POT_POS=>127 then amp=(235 * (POT_POS-127)) else amp=(235 * (128-POT_POS)) endif Lcdout $fe, 1, "POT_POS= ", #POT_POS ' Display POT Valu between 0-255 on line 1 ' Check if negtive or positive Ampere, only for - minus sign on LCD display IF POT_POS=>127 then LCDOut $fe,$C0, "AMP= ",DEC (amp/1000),".", DEC1 amp' Display +Amp on line 2 else LCDOut $fe,$C0, "AMP= -",DEC (amp/1000),".", DEC1 amp' Display -Amp on line 2 endif PAUSE 20 ' Constant 20mS pulses(low) between outpuls GOTO MainLoop ' Forever End




Bookmarks