12f675 A/d Miseries


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Ron,

    Well there are still several questions to be able to figure out what's wrong. Such as ... what is the voltage of the charging power source? What are the voltage divider resistor values. Where is the reading being taken, before or after the 10 ohm resistor. and probably a few others.

    However, there are a few things going on in the program that are suspect, but may not really be the problem.

    You seem to be trying to use both the built-in PBP ADCIN command, and manually manipulating the A/D registers. You should pick one method or the other, not both.

    In this line...
    Code:
    ANSEL = %01100001 ' Set GSIO 0 TO ANALOG A/D IN W/Frc
                      ' OTHER PINS TO DIGITAL
    It sets the A/D oscillator to FOSC/64, which is listed as "outside of recommended range" in the datasheet.

    It then starts a conversion, waits for it to finish, then discards the result. That is followed by an ADCIN statement that changes the oscillator to FRC, (since that was specified in the ADC_CLOCK define), and takes another reading.

    Again, this won't cause the problem you're seeing, but it's still not right.

    So maybe it's something with the questions in the first paragraph. ??
    <br>
    DT

  2. #2
    Join Date
    Dec 2005
    Posts
    23


    Did you find this post helpful? Yes | No

    Red face What it is!

    Hi Darrel

    The resistors are set up to provide a range of voltages somewhere between 0 and 4.75 volts to a/d for battery voltage of 0 to 20. I am still tweaking them to push it as close to 5 volts as possible. (will change the a/d numbers in the code accordingly to get as close to 12 and 16 volts as possible)
    I am not quite sure I understand your first email! Would you mind changing the code in my example to what it should be and re post it? I would really appreciate this, since this chip seems to have caused many an otherwise good code writer to "come unglued"! I do know that its Data Sheet is based on MPASM and Microchip's language; but I have tried for 10 years, and cannot make sense of that jibberish, anyway!!

    Thanks again!
    Ron

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Well, here's what I think you should have...
    Code:
    @  __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_OFF
    'INTERNAL OSCILLATOR (4 MHZ)
    'ENABLE WATCH DOG TIMER
    'ENABLE POWER UP TIMER
    'DISABLE MASTER CLEAR FUNCTION
    
    '****************************************************************
                       'VARIOUS OPERATION PARAMETERS
            
            'GPIO.0 IS A/D INPUT FROM VOLTAGE DIVIDER TO SET HIGH OR LOW
            'CHARGE. THIS FUNCTION TURNS ON 4710 MOSFET SWITCH (GPIO.4)
            'AND LED (GPIO.2) (STEADY ON) TO INDICATE FULL 3 AMP. CHARGE
            'TO BATTERY BETWEEN 12 VOLTS AND 16 VOLTS. OUTSIDE OF THESE
            'VOLTAGES, GPIO.4 IS LOW AND GPIO.2 FLASHES ON AND OFF, ONCE
            'PER SECOND. GPIO.3 IS MCLRE, PULLED TO Vcc BY 4.7K RESISTOR.
            'GPIO.0 AND GPIO.3 ARE INPUTS AND GPIO.2 AND GPIO.4 
            'ARE OUTPUTS. (OTHERS COME UP AS INPUTS
            '        HARDWARE CONNECTIONS
                    '====================
                    'GPIO.0 A/D INPUT TO ADC CHANNEL 0
                    'GPIO.1 N/C
                    'GPIO.2 OUTPUT TO CASE LED(flashes on and off)
                    'GPIO.3 MCLR PIN
                    'GPIO.4 HIGH TO PHOTOVOLTAIC MOSFET DRIVER
                    'GPIO.5 N/C                                
                    '=====================
                   
    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
    
    CMCON = 7               'TURN COMPARITORS OFF
    TRISIO = %001001        ' Set GSIO 0 & 3 TO INPUTS, others to OUTPUT
    ANSEL = %00110001 	    ' Set GSIO 0 TO ANALOG A/D IN W/Frc
    ADCON0.7 = 1	        ' Right Justify for 10-bit
    
    START:
        ADCIN 0, ADVAL0         ' Read A/D channel 0            
        IF (ADVAL0 <= 906) AND (ADVAL0 >= 604) Then   ; INRANGE
            High GPIO.4   'GO TO FULL 3 AMP RATE (MOSFET TURNED ON)
            High GPIO.2
        else                                          ; OUTRANGE
            Low GPIO.4   'GO TO TRICKLE CHARGE (MOSFET OFF-NO RESISTOR SHUNT IN)
            High GPIO.2  '10 ohm IN SERIES WITH CHARGER.
            Pause 500
            Low GPIO.2
            Pause 490
        endif    
    GoTo START
    
    End
    Also, there were some problem's with the CONFIG line. You can't see it in the post because it's all scruched up to the left. But, when you "Quote" post #1 you can see that there's no space between the @ and __CONFIG, and there's only 1 underscore before the CONFIG. There should be 2.

    Added: And there should be a space between __CONFIG and the first parameter _INTRC_OSC_NOCLKOUT.

    HTH,
    DT

  4. #4
    Join Date
    Dec 2005
    Posts
    23


    Did you find this post helpful? Yes | No

    Thumbs up Thanks Darrel!

    Darrel,
    The code you modified is working perfectly! Thanks very much! I was about to enter the proverbial "rubber room" over this one. I hope these examples will be helpful to others on the forum who have been messed over by the 12F675.
    By the way, have a happy new year!
    Ron

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    That's right. Bounce it off of us, before bouncing off the walls.

    Ha Ha, Happy New Year to you too!
    <br>
    DT

  6. #6
    Join Date
    Aug 2007
    Posts
    15


    Did you find this post helpful? Yes | No

    Default a/d 12f675 ,i can only use 1 and 2 not 500 to test input on a pot

    clean
    define adc_bits 10 'adc settings
    define adc_clock 3 ' adc setting
    define adc_sampleus 50 'adc setting
    intcon.6=1 'gloabal interrupt
    intcon.7=1 'gloabal interrupt
    pie1.6=1 'a/d interrupt
    pir1.6=1 'a/d interrupt

    adcon0=%10001111 'set an3 on ie gpio.4
    ansel=%00011000 ' sets fosc/8 and gpio.4[an3] as adc input
    cmcon=7 ' turn off comparator function
    trisio=%011000 'set gpio.4 as input and others as output



    'define variables
    rdg var word 'adc reading from an3
    mpin var gpio.2 ' music pin output to speaker
    led var gpio.0 'led output
    tone var word ' tone value for the sound

    'initial setting
    led=0

    'initial interrupt
    on interrupt goto testpot
    'program

    start:
    'reset led
    adcin 3,rdg 'get volt reading from an3 and place adc value in rdg

    goto start

    'isr
    disable
    testpot:

    if rdg =<1 then led=0
    if rdg =>2 then led=1 'turn on led if adc value is equal to or larger than 1


    tone=1+(rdg)*102 'converts adc value to a tone value of 1 to 120
    ' necessary to divide by 10 to avoid 65536 word limit
    'adc of 0=tone of 1, adc of 1023 = tone of 120
    sound mpin,[tone,20] 'provides a tone proportional to input volt duration = 20x12=120 min
    resume
    enable
    end

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mystified View Post
    clean
    What's that for?

    define adc_bits 10 'adc settings
    define adc_clock 3 ' adc setting
    define adc_sampleus 50 'adc setting
    Those aren't any good as they are written (unless there's something wrong with cut-and-paste, which happens sometimes)

    tone=1+(rdg)*102 'converts adc value to a tone value of 1 to 120
    ' necessary to divide by 10 to avoid 65536 word limit
    'adc of 0=tone of 1, adc of 1023 = tone of 120
    sound mpin,[tone,20] 'provides a tone proportional to input volt duration = 20x12=120 min
    Check your math...
    If rdg = 1 then
    tone = 1 + 1 * 102 = 103
    If rdg = 2 then
    tone = 1 + 2 * 102 = 205
    If rdg = 3 then
    tone = 1 + 3 * 102 = 307
    if rdg = 500 then
    tone = 1 + 500 * 102 = 51001
    Where is this 'divide by 10' you speak of?
    You declare tone as a word variable, yet the PBP manual states that values from 0-127 produce tones, 128-255 produces white noise, and therefore only values from 0-255 are legal, implying that tone should be a byte variable...
    Why not hook up an LCD to make sure your A/D is working in the first place? Then you can actually visualize your values to be output for tones.

Similar Threads

  1. How do I use 10 bit A/D on 8 bit Pic? 12F675
    By polymer52 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 1st April 2020, 20:10
  2. Need help with LM34 and 12F675
    By polymer52 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 6th December 2009, 13:06
  3. 12F675 A/D and GPIO sleep interrupt
    By macinug in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th September 2008, 14:39
  4. Need advice on A/D
    By james in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 24th August 2007, 19:30
  5. A/D converter fails?
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th February 2006, 18:57

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