Pic12f683 Cmcon0 = 7


Closed Thread
Results 1 to 26 of 26

Hybrid View

  1. #1
    Join Date
    Jun 2005
    Posts
    37

    Default Pic12f683 Cmcon0 = 7

    Hi! I just purchased some PIC12F683s and am having some problems. The simple program I wrote takes a 0 to 5V analog voltage from a 5k potentiometer and this adjusts HPWM. I have 0.1uF caps in place from VDD to VSS and another on the pot's wiper. At the moment, the HPWM drives an LED. Ultimately it will feed a mosfet that will control a small toy motor.

    Compiler - PisBasic Pro 2.47
    Using MicroCode Studio
    Pic - PIC12F683

    I get a syntax error on the line "CMCON0 = 7" which disables the comparators. Yes, I tried "0" and "O" and just "CMCON". As well, I am getting irratic behavoir from the HPWM where as I adjust the pot, the duty cycle jumps around irraticaly. I used an oscilloscope to verify the behavior.

    Any advice would be appreicated. The program is below;

    INTCON = %10001000 ‘internal oscillator
    OSCCON = %01110000 ‘ 8mHz
    CMCON0 = 7 'Comparators off
    GPIO = %00000000 'outputs low
    TRISIO = %00010000 'GP3 as input
    ANSEL = %00111000 'AN3 analog

    'Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS
    Define CCP1_REG GPIO 'PWM Output on gpio
    Define CCP1_BIT 2 'Bit 2

    ‘ Variables
    Posit var Word
    Speed var byte
    Pause 100

    Scan:
    ADCIN 3, Posit ' Read channel AN3 to Posit
    Speed = Posit/4
    HPWM 1,Speed,1000
    Pause 10
    Goto Scan
    End

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by penelopepug View Post
    ...and another on the pot's wiper.
    Remove the cap.

    Quote Originally Posted by penelopepug View Post
    ...I get a syntax error on the line "CMCON0 = 7" which disables the comparators. Yes, I tried "0" and "O" and just "CMCON".
    Select the correct PIC model from the drop down menu in MicroCode Studio.

    Quote Originally Posted by penelopepug View Post
    ...
    INTCON = %10001000 'internal oscillator
    OSCCON = %01110000 '8mHz
    Add, DEFINE OSC 8.

    Quote Originally Posted by penelopepug View Post
    ...
    Define CCP1_REG GPIO 'PWM Output on gpio
    Define CCP1_BIT 2 'Bit 2
    Not sure why you used these?
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by penelopepug View Post
    Hi! I just purchased some PIC12F683s and am having some problems. The simple program I wrote takes a 0 to 5V analog voltage from a 5k potentiometer and this adjusts HPWM. I have 0.1uF caps in place from VDD to VSS and another on the pot's wiper. At the moment, the HPWM drives an LED. Ultimately it will feed a mosfet that will control a small toy motor.

    Compiler - PisBasic Pro 2.47
    Using MicroCode Studio
    Pic - PIC12F683

    I get a syntax error on the line "CMCON0 = 7" which disables the comparators. Yes, I tried "0" and "O" and just "CMCON". As well, I am getting irratic behavoir from the HPWM where as I adjust the pot, the duty cycle jumps around irraticaly. I used an oscilloscope to verify the behavior.

    Any advice would be appreicated. The program is below;

    INTCON = %10001000 ‘internal oscillator
    OSCCON = %01110000 ‘ 8mHz
    CMCON0 = 7 'Comparators off
    GPIO = %00000000 'outputs low
    TRISIO = %00010000 'GP3 as input
    ANSEL = %00111000 'AN3 analog

    'Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS
    Define CCP1_REG GPIO 'PWM Output on gpio
    Define CCP1_BIT 2 'Bit 2

    ‘ Variables
    Posit var Word
    Speed var byte
    Pause 100

    Scan:
    ADCIN 3, Posit ' Read channel AN3 to Posit
    Speed = Posit/4
    HPWM 1,Speed,1000
    Pause 10
    Goto Scan
    End
    Hello,
    Without checking to see if this code works, and without reading for understanding, I did compile as presented below and it compiles. I found 3 things which prevented it from compiling. You used ` instead of ' on some of your comments and you defined
    Define CCP1_REG GPIO 'PWM Output on gpio
    Define CCP1_BIT 2 'Bit 2
    which are already defined in the 12f683.bas file. I just commented them out.
    HTH
    JS
    Oh, BTW, a scratchy pot can do wild things when used here too, and Sayzer will never steer you wrong.
    Code:
    INTCON = %10001000 'internal oscillator
    OSCCON = %01110000 ' 8mHz
    CMCON0 = 7 'Comparators off
    GPIO = %00000000 'outputs low
    TRISIO = %00010000 'GP3 as input
    ANSEL = %00111000 'AN3 analog
    
    'Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS
    'Define CCP1_REG GPIO 'PWM Output on gpio
    'Define CCP1_BIT 2 'Bit 2
    
    ' Variables
    Posit var Word
    Speed var byte
    Pause 100
    
    Scan:
    ADCIN 3, Posit ' Read channel AN3 to Posit
    Speed = Posit/4
    HPWM 1,Speed,1000
    Pause 10
    Goto Scan
    End
    Last edited by Archangel; - 11th July 2007 at 18:42.
    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.

  4. #4
    Join Date
    Jun 2005
    Posts
    37


    Did you find this post helpful? Yes | No

    Default PIC12F683 Problems

    Thanks for looking at this for me. I should have realized that the "bas" file sets up the HWPM for me. However I am not sure this is the source of the problem. I did look at the output of the pot and it is perfectly clean with and without the capacitor. It seems to be related to the anolog sampling or calculation (I think). As for the compiling issue, I did select the correct PIC but no matter what I do the CMCON0 shows up as a syntax error for me. I ended up commenting it out and moving the analog over to a differing port so as to not have to worry about the error.

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by penelopepug View Post
    However I am not sure this is the source of the problem. I did look at the output of the pot and it is perfectly clean with and without the capacitor. It seems to be related to the anolog sampling or calculation (I think).
    The problem probably stems from the fact that you are most likely updating the duty cycle in the middle of performing a cycle. The datasheets talk about that sort of thing. What happens if you just run the program in a loop that doesn't change the duty cycle?
    As far as the A/D output, are you sure the A/D output (the number returned by the ADCIN command) is smooth in the first place? Maybe a 10ms pause isn't enough (not likely), maybe too much. Add in a bit of code to average out the duty cycle itself, software averaging of some sort, move the duty cycle around 'slower'...see what happens.

    And as far as CMCON goes, just POKE the value into the appropriate register and see what happens.

  6. #6
    Join Date
    Jun 2005
    Posts
    37


    Did you find this post helpful? Yes | No

    Default PIC12F683 Problems

    Thanks skimask. You've given me some things to try. I'll post my findings assuming I resolve the problems. Thanks again.

  7. #7
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    ....You used ` instead of ' on some of your comments.
    penelopepug,

    May be you missed what Joe talks about.

    Pay attention to these characters;
    `
    '


    as you know, they are not the same characters and will give you syntax errors.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  8. #8
    Join Date
    Jun 2005
    Posts
    37


    Did you find this post helpful? Yes | No

    Default PIC12F683 Problems

    Quote Originally Posted by sayzer View Post
    penelopepug,

    May be you missed what Joe talks about.

    Pay attention to these characters;
    `
    '


    as you know, they are not the same characters and will give you syntax errors.
    Hi Sayzer. I had retyped that line and copied and pasted it a few times thinking something hidden was the problem. However I'll take a close look at that, hopefully tonight. Thanks again.

  9. #9


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    Hello,
    Edited.
    Code:
    INTCON = %10001000 'internal oscillator
    OSCCON = %01110000 ' 8mHz
    CMCON0 = 7 'Comparators off
    GPIO = %00000000 'outputs low
    TRISIO = %00010000 'GP4 as input
    ANSEL = %00111000 'AN3 analog
    
    'Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS
    'Define CCP1_REG GPIO 'PWM Output on gpio
    'Define CCP1_BIT 2 'Bit 2
    
    ' Variables
    Posit var Word
    Speed var byte
    Pause 100
    
    Scan:
    ADCIN 3, Posit ' Read channel AN3 to Posit
    Speed = Posit/4
    HPWM 1,Speed,1000
    Pause 10
    Goto Scan
    End
    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

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

  11. #11


    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

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

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Thermo 7 segments - little problem
    By fratello in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 27th July 2013, 07:31
  3. RS485 bus - starting probem
    By wurm in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th January 2010, 13: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, 19:16
  5. code conversion
    By saturnX in forum mel PIC BASIC
    Replies: 19
    Last Post: - 3rd October 2005, 17: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