12F675 compare voltage help.


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Posts
    91

    Default 12F675 compare voltage help.

    I am trying to figure out how to use a 12F675 to compare voltage.
    This will eventually be used to meaure a current load.

    I am sending the output to serial and checking it via hyperterm just so I can see whats going on.

    I have the chip connected like this.
    1 + 3
    2 NC
    3 NC
    4 NC
    5 NC
    6 pin2 serial.
    7 testing connected to ground/pos/nothing.
    8 ground and serial ground.

    Here is my code most copied off this forum.
    Code:
    @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
        ' Internal Oscillator
        ' Enable watch dog timer
        ' Enable power up timer
        ' Disable MCLR pin
        ' Enable brown out detect
    
    DEFINE OSCCAL_1K 1
    INCLUDE "modedefs.bas"
    CMCON = 7 ' turn off analog comparator
    DEFINE OSC          4
    DEFINE ADC_BITS     10  '10 BIT A/D CONVERSION RESULT
    DEFINE ADC_CLOCK    3   'INTERNAL A/D RC CLOCK
    DEFINE ADC_SAMPLEUS 50  'SET SAMPLE TIME IN MICROSECONDS
    adval0  VAR WORD		'Create adval0 to store result
    
    TRISIO = %000001        ' Set GSIO 0 & 3 TO INPUTS, others to OUTPUT
    ANSEL.0 = 1             ' Set GSIO 0 to ANALOG
    ADCON0.7 = 1	        ' Right Justify for 10-bit
    I var byte
    
    
    
    
    
    
    
    Pause 2000 
    
    
    loop:
        ADCIN 0, ADVAL0         ' Read A/D channel 0            
        SerOut GPIO.1,N2400,["Result ",#adval0,13,10]
    
    Pause 200
    GoTo loop
    When I have pin 7 connected to ground.
    I get all 0's
    When I have pin 7 connected to +
    I get Result 1020
    When I disconnect 7 from + I get Result 600 and it slowly goes down to 113 to 140.

    Can someone explain to me what this is telling me?

  2. #2
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    The ADC is 10-bits so the highest possible reading is 1023. Your 1020 indicates 3V (if that's your Vcc).

    The 600 that fades indicates the ADC input is floating.

    The 0 reading indicates the 0V.

  3. #3
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Ok thanks that helps but what does it mean its floating?

    That mean the VCC is floating or when the ADC is connected to nothing its floating?

  4. #4
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    The ADC input is floating and the reading is meaningless if it has no connection.

  5. #5
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Thank you very much.

  6. #6
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default Little more help

    I am stuck again.

    I multiply by 1000 to shift where the decimal will be.
    The problem is my first calculation is
    1022*1000 comes out 38960 instead of 1022000 How do I keep my whole number?


    I tried this as well
    dummy VAR WORD
    adval0=1019
    dummy = adval0*1000*3
    adval0 = div32 1023


    Gives me 111... Should be giving me 2988 or something...
    Last edited by geckogrotto; - 1st February 2007 at 17:03. Reason: Div32

Similar Threads

  1. high voltage high frequency H-Bridge
    By George in forum Off Topic
    Replies: 6
    Last Post: - 27th April 2009, 11:50
  2. Expanded Scale Voltmeter
    By Pic_User in forum Schematics
    Replies: 6
    Last Post: - 8th February 2008, 20:32
  3. make a low voltage output from a PIC pin
    By emptyset in forum General
    Replies: 1
    Last Post: - 8th February 2008, 19:20
  4. Help with final project
    By OvERKiLL in forum General
    Replies: 4
    Last Post: - 15th December 2006, 20:35
  5. Low Voltage Detection
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th January 2005, 18:29

Members who have read this thread : 0

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

Posting Permissions

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