PIC 16f877 A/D conversion Allegro ACS712


Closed Thread
Results 1 to 33 of 33

Hybrid View

  1. #1
    Join Date
    Mar 2011
    Location
    Bangkok Thailand
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: PIC 16f690 Allegro ACS712 + -30Amp

    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

    Name:  ASC714 to LCD.jpg
Views: 40376
Size:  87.8 KB
    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
    

    Last edited by Archangel; - 7th June 2011 at 18:21. Reason: non;add code tags

Similar Threads

  1. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 01:48
  2. A/D conversion problem in 18F2520, 2523, 2550 etc.
    By selimkara in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th March 2008, 16:26
  3. 16f877 A/D help
    By 3adam in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 25th January 2008, 04:06
  4. A/D converter fails?
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th February 2006, 18:57
  5. Strange A/D conversion...
    By Christos_K in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th June 2005, 01:35

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts