Beginner in need of help !!


Closed Thread
Results 1 to 40 of 72

Hybrid View

  1. #1
    Join Date
    Jan 2015
    Posts
    45


    Did you find this post helpful? Yes | No

    Angry Re: Beginner in need of help !!

    Okay I have had a go & failed What am I doing wrong?

    Code:
    'PIC12f683
    
    #CONFIG 
       __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
    #ENDCONFIG
    
    DEFINE OSC 4 '4mhz ocsillator
    ANSEL = %00000010 'pin 6 analog
    CMCON0 = %00000100 'comparator mode
    VRCON = %00001000 'voltage reference
    TRISIO = %00000010 'pin 6 input
    
    POTEN VAR CMCON0.1 'pot pin 6
    LED VAR GPIO.2 'led pin 5
    
    PAUSE 20
    
    main:
    IF CMCON0.1 = 1 THEN
    HIGH LED
    ELSE
    LOW LED
    ENDIF
    GOTO main

  2. #2
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: Beginner in need of help !!

    Rob,

    Glad to see your working through the design and issues.
    You are very close.

    Here are a couple of things you need to correct.
    1. VRCON: Look at the register description in "Register 8-3" on page 53 of the datasheet.
    In your program you are setting VRCON like this: VRCON = %00001000 'voltage reference
    There are more bits in the register that you need to take into account.
    A. You have bit7=0 which does this "0 = CVREF circuit powered down, no IDD drain and CVREF = VSS". This turns OFF the internal reference voltage.
    You need to change this to "1", 1 = CVREF circuit powered on, to turn on the internal reference voltage circuit.
    B. You have bit5 = 0 which does this "VRR: CVREF Range Selection bit 0=High Range"
    This changes your CVref equation and result to this: "VRR = 0, CVREF = (VDD/4) + (VR3:VR0 X VDD/32)", which when you plug in your values you get this
    for your reference voltage. (3.3/4) + (8/32) = (0.825) + (0.25) = 1.075 Vdc. Now this may be what you were actually trying to do, if so then your are good.

    2. In your main loop you are attempting to test the output of the Comparator like this: "IF CMCON0.1 = 1 THEN"...
    Look at the CMCON0 register description in "Register 8-1" on page 47 of the datasheet and compare that with the "CMCON0.1 = 1" above.
    You are testing bit1 of the CMCON0 register, that is what the ".1" does. xxxx.1 says I want to look at bit1 of xxxx.
    Is this the bit you need to check for the Comparator Output? If you're not sure have a look at "FIGURE 8-3" on page 49 and look at the figure for the
    CM Mode you are using "100". That diagram indicates what the Comparator Output is by name.

    Check and correct this.

    3. Lastly, and somewhat obscure in the DS, you need to determine how you want the Comparator to test and output.
    As I understand you want to check the input pin voltage against your "1.075 Vdc" reference you are setting up internally and have the following outcomes:
    If the input is "Lower than 1.075 Vdc" you want the LED to be OFF and you want the LED to be "ON when the input is Higher than 1.075 Vdc".

    To get these results you need to take a look at a couple of items in the datasheet.
    A. Look at CMCON0, "Register 8-1" on page 47, and review the information for bit6 and bit4.
    Also look at "TABLE 8-1" on page 48.
    Between these two, you should be able to piece together how you need to configure the operation to get your desired "Output" of the Comparator.

    You are getting close, hopefully these additional points will get you further on your way.

    Regards,
    Regards,
    TABSoft

  3. #3
    Join Date
    Jan 2015
    Posts
    45


    Did you find this post helpful? Yes | No

    Default Re: Beginner in need of help !!

    Hi Tabsoft, thanks a lot for your help I appreciate it. I will go back through everything you have stated & set it up right this time. I did think there were other bits to change but didnt want to mess as I didnt know what I was doing, but ai should now with your info.

    Thanks again, I will let you know how it goes.
    Rob

  4. #4
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: Beginner in need of help !!

    Rob,

    One correction in my earlier post.

    The CVref calculation for High Range is CVREF = (VDD/4) + (VR3:VR0 X VDD/32).
    Using your input values of VDD=3.3 and VR3:VR0=8, the calculation will come out like this.
    (3.3/4) + (8 x (3.3/32) = (0.825) + (8 x 0.103125) = (0.825) + (0.825) = 1.65 Vdc

    If you use Low Range then here is the info:
    CVREF = (VR3:VR0/24) x VDD = (8/24) x 3.3 = 0.333 x 3.3 = 1.1 Vdc

    Regards,
    Regards,
    TABSoft

  5. #5
    Join Date
    Jan 2015
    Posts
    45


    Did you find this post helpful? Yes | No

    Default Re: Beginner in need of help !!

    Hi Tabsoft,

    Right I have changed the bits in the VRCON to the right stuff, so I think that is right now. I did change bits in the CMCON0 but none of it seemed to make a difference, so I have put it back to how it was. I'm thinking either I'm testing the wrong bit still or my actual hardware setup is wrong.

    Maybe you can point something out?

    BTW I am using the low range Also this is correct - As I understand you want to check the input pin voltage against your "1.1" reference you are setting up internally and have the following outcomes: If the input is "Lower than 1.075 Vdc" you want the LED to be OFF and you want the LED to be "ON when the input is Higher than 1.075 Vdc".

    Code -

    Code:
    'PIC 12F683
    
    
    #CONFIG 
       __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
    #ENDCONFIG
    
    
    DEFINE OSC 4 '4mhz ocsillator
    ANSEL = %00000010 'pin 6 analog
    CMCON0 = %00000100 'comparator mode
    VRCON = %10101000 'voltage reference
    TRISIO = %00000010 'pin 6 input
    
    
    POT1 VAR CMCON0.2 'pot pin 6
    LED VAR GPIO.2 'led pin 5
    
    
    PAUSE 20
    
    
    main:
    IF POT1 = 1 THEN 
    HIGH LED
    ELSE
    LOW LED
    ENDIF
    GOTO main
    Thanks again,
    Rob
    Last edited by robbo78; - 25th January 2015 at 11:59.

  6. #6
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: Beginner in need of help !!

    Rob,

    Yes you're not testing the correct bit for the actual output of the Comparator..

    Look at my post again where I listed the things you need to correct. Look at item 2.
    I point you to where you can find the answer of which bit in which register to test.
    I also point you to where you can determine what the output of the comparator will be for different configurations and physical connections.

    Have a read of this info again, I'm sure you'll get it.

    Regards
    Regards,
    TABSoft

  7. #7
    Join Date
    Jan 2015
    Posts
    45


    Did you find this post helpful? Yes | No

    Default Re: Beginner in need of help !!

    Hi Tabsoft, okay had another read at first it was just going over my head. Am I right in saying I need to read bit 6 of CMCON0? So CMCON0.6?

    Thanks,
    Rob

Similar Threads

  1. Beginner help!
    By Recognize in forum General
    Replies: 14
    Last Post: - 26th April 2012, 14:55
  2. pic24 beginner
    By robertpeach in forum General
    Replies: 23
    Last Post: - 13th August 2009, 11:57
  3. need help! to beginner
    By emilhs in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 6th May 2009, 18:44
  4. Beginner at PB
    By alphahr in forum Off Topic
    Replies: 1
    Last Post: - 21st April 2008, 17:43
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23: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