Pic12f683 Cmcon0 = 7


Closed Thread
Results 1 to 26 of 26

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by StoneColdFuzzy View Post
    OK, I'm still trying to understand this and use code, so I thought that I would revive this thread.

    Above, the code has "ANSEL = %00111000 'AN3 analog" To me it looks like AN4 and 5 are also made analog. Is this needed? if it is not needed, I should be able to use:
    Code:
    ANSEL = %00001000  ' AN3 analog
    ~ Dave
    For the 12F683 there is no AN4 and AN5, those bits control the data conversion clock. see the Data sheet page 33.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    For the 12F683 there is no AN4 and AN5, those bits control the data conversion clock. see the Data sheet page 33.
    OK, yes, I see that now. Are they to be set to 1 for this application? Where may I find more information in layman's terms to help me understand what that is?

    ~ Dave

  3. #3
    Join Date
    Nov 2008
    Posts
    41


    Did you find this post helpful? Yes | No

    Default

    This may help you a bit. I've been playing with the 12F683.

    Code:
    @	__CONFIG _INTOSCIO & _FCMEN_OFF & _IESO_OFF & _BOD_OFF & _BOD_OFF & _CP_OFF & _MCLRE_ON & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF
    
    DEFINE OSC 8           ' Internal 8MHz
    DEFINE ADC_BITS 8      ' 8-bit resolution
    DEFINE ADC_CLOCK 2     ' Set clock source to Frc/32
    DEFINE ADC_SAMPLEUS 50 ' Sample time in uS before A/D conversion is started
    
    CMCON0 = 7   			'Comparators off
    ADCON0 = %00000001		'ADC enabled and right justified
    ANSEL = %00001000		'GPIO.0 and GPIO.1 analog input
    INTCON = 0				'INTERRUPTS off
    OSCCON = %01110000		'8 Mhz
    TRISIO = %111011		'GPIO2 output
    GPIO = %00010000 		' All outputs = 0 on boot

  4. #4


    Did you find this post helpful? Yes | No

    Default

    astouffer, thank you.

    What's wrong when I can compile multiplication but not division? I get this error "macro div?ctb not found in macro file."

    This compiles OK:
    Code:
    width = 510 * mon
    This will not compile:
    Code:
    width = 510 / mon
    ~ Dave

  5. #5


    Did you find this post helpful? Yes | No

    Default

    I've been playing with this code to change HPWM depending on a monitored voltage. The original code at the top of this thread works, but it's erratic.

    I've changed things around a bit to fit my needs and it runs a little bit better, but it's still erratic, probably due to refreshing the duty cycle all of the time. I'm looking for suggestions to make this run a little more smooth. Any suggestions?

    ~ Dave

    Code:
    Mon var Word
    Width var byte
    Pause 100
    
    Main:
        ADCIN 3, mon ' Read channel AN3 to Mon
        width = mon*1
        if width <= 2 then OneP
        if width > 2 then twoP
        
    OneP:
        hpwm 1,255,2000
        pause 1000
        goto main
        
    TwoP:
        hpwm 1,32,2000
        pause 1000
        goto main
        
    end

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by StoneColdFuzzy View Post
    I've been playing with this code to change HPWM depending on a monitored voltage. The original code at the top of this thread works, but it's erratic.

    I've changed things around a bit to fit my needs and it runs a little bit better, but it's still erratic, probably due to refreshing the duty cycle all of the time. I'm looking for suggestions to make this run a little more smooth. Any suggestions?

    ~ Dave

    Code:
    Mon var Word
    Width var byte
    Pause 100
    
    Main:
        ADCIN 3, mon ' Read channel AN3 to Mon
        width = mon*1
        if width <= 2 then OneP
        if width > 2 then twoP
        
    OneP:
        hpwm 1,255,2000
        pause 1000
        goto main
        
    TwoP:
        hpwm 1,32,2000
        pause 1000
        goto main
        
    end
    Anyone?

    ~ Dave

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Dave - What is your definition of 'erratic'?

    width = mon*1

    Oh... Can you tell me what is the point of the *1 part of this line?

    Basically your program states that if mon is >2 then your HPWM will be at around 12.5% otherwise it will be solid ON. There's not much else that happens... or at least it would do if you remembered a GOTO MAIN after the last IF statement!!! Because as it is, your code is slamming straight into the OneP section.

    You could rewrite your code as...

    Code:
    Main:
        ADCIN 3, mon ' Read channel AN3 to Mon
        width = mon
        if width > 2 then 
    	hpwm 1,32,2000
    	else
    	hpwm 1,255,2000
    	endif
        pause 1000
        goto main
    I'm also assuming you've set TRISIO and such properly.

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 07:14
  2. Thermo 7 segments - little problem
    By fratello in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 27th July 2013, 08:31
  3. RS485 bus - starting probem
    By wurm in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th January 2010, 14:35
  4. Working with indivividual bytes of an array
    By J_norrie in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 22nd January 2007, 20:16
  5. code conversion
    By saturnX in forum mel PIC BASIC
    Replies: 19
    Last Post: - 3rd October 2005, 18:17

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