Beginner in need of help !!


Closed Thread
Results 1 to 40 of 72

Hybrid View

  1. #1
    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

  2. #2
    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.

  3. #3
    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

  4. #4
    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

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


    Did you find this post helpful? Yes | No

    Default Re: Beginner in need of help !!

    Exactly!

    CMCON0 Register:
    bit 6 COUT: Comparator Output bit.
    This is the logic bit output of the Comparator.

    CM: Comparator Mode = 100
    Name:  Picture1.png
Views: 760
Size:  33.8 KB

    With this setup the comparator is comparing VIN- (CIN-/GP1) to VIN+ (which is not an external pin but it is "From CVREF Module", internal voltage reference)
    So you need to look at the description of COUT in the CMCON0 register listed below AND you need to look at Table 8-1 in the DS.
    This will help you work out what value CMCON0.6 will be based upon a given input on GP1.
    Take note that CINV is a configuration bit within the CMCON0 register that determines the logic polarity of COUT.

    COUT: Possible values
    When CINV = 0:
    1 = VIN+ > VIN-
    0 = VIN+ < VIN

    When CINV = 1:
    1 = VIN+ < VIN-
    0 = VIN+ > VIN
    Regards,
    TABSoft

  6. #6
    Join Date
    Jan 2015
    Posts
    45


    Did you find this post helpful? Yes | No

    Default Re: Beginner in need of help !!

    Brilliant! Thanks for the info again your the best! I should be able to get this working how I want it to now, then & only then will I move onto interupt with it.

    Thanks again,
    Rob

  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, I got the comparator working perfectly so I decided to move onto adding an interrupt, which believe it or not hasn't worked. Here is the code I have fully written, maybe you can help where I have gone wrong?

    Thanks,
    Rob

    You will probably have a laugh at this, as its probably completely wrong lol


    Code:
    'PIC 12F683
    
    #CONFIG 
       __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
    #ENDCONFIG
    
    PAUSE 20 'wait for hardware to settle
    
    DEFINE OSC 4 '4mhz ocsillator
    ANSEL = %00000010 'pin 6 analog
    CMCON0 = %00000100 'comparator mode
    VRCON = %10101000 'voltage reference
    TRISIO = %00000010 'pin 6 input
    
    ON INTERRUPT GOTO SLSELECT 'interrupt handler is slselect
    INTCON = %11001000 'enable GIE and GPIE; clear GPIF
    IOC = %00000010 ' enable IOC1 (GPIO.1 Interrupt on change)
    PIE1 = %00001000 'enable comparator interrupt
    
    POT1 VAR CMCON0.6 'read potentiometer
    LED VAR GPIO.2 'led pin 5
    
    ENABLE
    main:
    HIGH LED 'light led
    GOTO main 'repeat
    
    DISABLE 'disable interrupts in handler
    SLSELECT:
    IF POT1 = 1 THEN 'if <1.1v sleep
    NAP 1
    ELSE
    ENDIF
    
    INTCON = %10001000  'enable GIE and GPIE; clear GPIF
    PIR1 = %00000000 'reset CMIF
    RESUME 'where left off
    ENABLE 'enable interrupts

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