CCP1CON and CCP2CON strange behaviour - need some advice


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: CCP1CON and CCP2CON strange behaviour - need some advice

    I've been trying to resolve this for days... would welcome some pointers as to what is happening here

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: CCP1CON and CCP2CON strange behaviour - need some advice

    OK...

    Looked at the original code for the 2550 and the config settings are

    Code:
    asm
    __CONFIG    _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L  
    __CONFIG    _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEM_OFF_1H & _IESO_OFF_1H 
    __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L  & _BORV_2_2L  & _VREGEN_ON_2L   
    __CONFIG    _CONFIG2H, _WDT_OFF_2H 
    __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H 
    __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L 
    endasm
    Note the CCP2MX fuse setting. So I added this to the fuse settings for the 4520

    Code:
    ASM 
      __CONFIG    _CONFIG1H, _OSC_HSPLL_1H
      __CONFIG    _CONFIG2L, _PWRT_ON_2L  
      __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
      __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H 
      __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    But get "symbol not previously defined (CCP2MX_ON_3H)"

    So I checked the INC file to see that everything was commented out, and it was

    Code:
    ;****************************************************************
    ;*  18F4520.INC                                                 *
    ;*                                                              *
    ;*  By        : Leonard Zerman, Jeff Schmoyer                   *
    ;*  Notice    : Copyright (c) 2008 microEngineering Labs, Inc.  *
    ;*              All Rights Reserved                             *
    ;*  Date      : 09/15/08                                        *
    ;*  Version   : 2.60                                            *
    ;*  Notes     :                                                 *
    ;****************************************************************
            NOLIST
        ifdef PM_USED
            LIST
            "Error: PM does not support this device.  Use MPASM."
            NOLIST
        else
            LIST
            LIST p = 18F4520, r = dec, w = -311, w = -230, f = inhx32
            INCLUDE "P18F4520.INC"   ; MPASM  Header
            ;__CONFIG    _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
            ;__CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
            ;__CONFIG    _CONFIG3H, _CCP2MX_PORTC_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
            ;__CONFIG    _CONFIG4L,  _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L
            NOLIST
        endif
            LIST
    EEPROM_START	EQU	0F00000h
    BLOCK_SIZE	EQU	64
    But noticed the way the fuse was worded so copied that to the PBP code thus

    Code:
    ASM 
      __CONFIG    _CONFIG1H, _OSC_HSPLL_1H
      __CONFIG    _CONFIG2L, _PWRT_ON_2L  
      __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
      __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_PORTC_3H 
      __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    It compiled fine, but the LED on PORTC.2 (CCP1CON) still flashes whilst the LED fades up and down and the case statement is anything other than NIGHT (off) It's as if something is taking the pin low at regular interval

    I would really appreciate some help here guys

  3. #3
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: CCP1CON and CCP2CON strange behaviour - need some advice

    LOL - it does the same thing if I comment out the settings

    Code:
    '****************************************************************
    'Port settings
    
    'CCP1CON = %00001100             ' 
    'CCP2CON = %00001100             '     
    TRISA  = %00000111              'set PORTA as all output apart from 0,1,2
    TRISB  = %00000011              'set PORTB as all output apart from 0&1
    TRISC  = %01000000              '
    T2CON     = %00000100  ' Timer2 ON + 1:1 prescale
                         
    SCLpin var PORTC.3               ' RTC pin - clk
    SDApin var PORTC.4               ' RTC pin - data
    '****************************************************************
    so it appears to be ignoring the code altogether

  4. #4
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: CCP1CON and CCP2CON strange behaviour - need some advice

    100 views and not one comment or suggestion... surely someone has some idea as to what's happening ????

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: CCP1CON and CCP2CON strange behaviour - need some advice

    Hi,
    I think you need to try and recreate the issue with as little code as possible. Start from scratch, can you get a steady duty cycle out of both modules without the aditional on/off toggling or does the toggling happen as soon as you try to get PWM out on PortC.2?

    /Henrik.

  6. #6
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: CCP1CON and CCP2CON strange behaviour - need some advice

    This is actually a somewhat tricky problem. Without spending a couple hours going through this for you, I'm going to take a shot in the dark. Your description of the problem suggests the value of CCP1 is getting changed at an inopportune time, or the output is being switched to C2 temporarily or there's a bad TRISC or ADCON statement. The most likely cause is that you have a lot of code in your interrupt routine, and you go to it often. It's possible that CCP1 getting set / reset occasionally at unfortunate times because you are off servicing the interrupt. I'd recommend that the interrupt routine set a flag only, or simply increment Tick_Tmr and do the value comparisons (IF..THEN) as part of your main loop.
    Just a guess, and maybe a new direction for you to poke.

  7. #7
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: CCP1CON and CCP2CON strange behaviour - need some advice

    Henrik, thanks for the reply and suggestion.

    The pulsing only occurs when the conditions are matched for the start of the lighting phase. For example, if the lighting period is set for an hour between 10:00 and 11:00, with a 5 minuet fade up and fade down times, this pulsing happens on C.2 when the time is => 10:00 and <=11:00. But the intensity of the LED fades up correctly between 10:00 and 10:05 and down correctly between 10:55 and 11:00. The thing that really perplexes me is that C.1 works as it should with the LED increasing in brightness, stays lit at full brightness and then fades down until turning off at the set times

  8. #8
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: CCP1CON and CCP2CON strange behaviour - need some advice

    I seriously believe it's something to do with the port config as Charles has mentioned. It's as if the code is ignoring the configuration of this register.

    I did think that the problem may be due to the fact that the RTC uses C.3 and C.4 for SLC and SDA lines but if I have read the datasheet correctly, If bits 3-0 are set to 1100 and bits 6 & 7 are set to 00 then P1B, P1C and P1D are set to port pins, but then these appear to point to pins D5, D6 and D7 rather than Port C pins - so that would rule that out

    Given the fact that I can comment out the settings for the register and the code behaves exactly the same way does confuse me (easily done) and the fact that channel 2 works ok and it's channel 1 that is screwing up

Similar Threads

  1. Strange IT behaviour
    By MikeBZH in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 10th February 2012, 10:00
  2. Strange behaviour
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th October 2009, 23:35
  3. Strange Serout Behaviour
    By bluesmoke in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th August 2009, 05:12
  4. Strange ADC behaviour
    By ruijc in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 12th December 2007, 21:03
  5. strange int behaviour
    By tom in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th November 2005, 16:41

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