Menu

Oscillator problem on 18F47K42

Help
Peter
2018-04-07
2018-04-09
  • Peter

    Peter - 2018-04-07

    Hi,
    I started to work on a new project including the 18F47K42.

    It seems like GCB is setting the wrong osc-settings on this mcu.
    Stripped down code below.
    The PWM-output is about 25kHz instead of 100kHz and
    the led-flashing is also about 4 times longer of what it needs to be.

    using latest available GCB 0.98.01 and chipfile from gcbasic/trunk/chipdata

    any help is highly appreciated

    #chip 18F47K42,16
    
    #startup InitPPS, 85
    Sub InitPPS
      UNLOCKPPS
        RC1PPS  = 0x0009
      LOCKPPS
    End Sub
    
    #define LED_GREEN   PORTA.5
    #define PWM_BOOST   PortC.1
    
    DIR LED_GREEN OUT
    DIR PWM_BOOST OUT
    
    LED_GREEN=1
    
    hpwm 1, 100, 25   '100kHz, 10% duty
    
    do
      LED_GREEN = !LED_GREEN
      wait 100 ms
    loop
    
     
  • Anobium

    Anobium - 2018-04-07

    Please post the ASM file generated.

     
  • Peter

    Peter - 2018-04-07

    Hi and wow - what a quick reply :)

    as requested here is the ASM-file

     
  • Anobium

    Anobium - 2018-04-07

    Many errors - I see nothing incorrect with osc.

    1. Please use PPSTool to correct the PPS settings
    2. You are address PWM1 when the PPS can only be set to PMW5, PMW6, PMW7 or PMW8. Please use PPSTool to see the potential options.
    3. You are using an 8bit PWM call when you need use HPWM 10 Bit. See HPWM 10 Bit
      in the Help.

    This worked for me. Same family of chip ( I happen to be just testing the PICKit2Plus programming... so, I used a Pk2 to program the 18F24K42!!.. sign up for the test program!)

    I have scope reading at 100Khz, Duty 10%. Two LEDS.. one flashing and one dim.

    Anobium

     #chip 18F24K42,16
    
        'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.5.15
        'PinManager data: v1.65.1
        '
        'Template comment at the start of the config file
        '
        #startup InitPPS, 85
    
        Sub InitPPS
    
                'Module: PWM5
                RC1PPS = 0x000D    'PWM5 > RC1
    
        End Sub
        'Template comment at the end of the config file
    
    #define LED_GREEN   PORTA.5
    #define PWM_BOOST   PortC.1
    
    DIR LED_GREEN OUT
    DIR PWM_BOOST OUT
    
    LED_GREEN=1
    
    hpwm 5, 100, 25, 2   '100kHz, 10% duty
    
    do
      LED_GREEN = !LED_GREEN
      wait 100 ms
    loop
    
     
  • Peter

    Peter - 2018-04-07

    Hi,
    I copy/pasted ur code and adjusted only chip to 18F47K42 and wait to 125 ms.
    got exact the same problem -> 25kHz(measured 24,51khz) and led flashing exactly once per second.
    Perhaps a problem within the chipdata-file?

    I'm programming the chip with PICkit3 and MPlabIPE4.15

    btw: this is the PPStool-output I used and stripped to the needed parts:

        'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.5.11
        'PinManager data: v1.55
        '
        'Template comment at the start of the config file
        '
        #startup InitPPS, 85
    
        Sub InitPPS
    
                'Module: CCP1
                RC1PPS = 0x0009    'CCP1 > RC1
                CCP1PPS = 0x0011    'RC1 > CCP1 (bi-directional)
    
        End Sub
        'Template comment at the end of the config file
    
     

    Last edit: Peter 2018-04-07
  • Anobium

    Anobium - 2018-04-07

    Sorry you are using CCP1. This would be the correct code.

    It is good practice to lead the PPSTool in the code. Why? It is very hard to decifer without the datasheet and that is not really needed if the whole text is present. :-). Hence my error on PWM v CCP.

    #chip 18F24K42,16
    
        'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.5.15
        'PinManager data: v1.65.1
        '
        'Template comment at the start of the config file
        '
        #startup InitPPS, 85
    
        Sub InitPPS
    
                'Module: CCP1
                RC1PPS = 0x0009    'CCP1 > RC1
                CCP1PPS = 0x0011    'RC1 > CCP1 (bi-directional)
    
        End Sub
        'Template comment at the end of the config file
    
    #define LED_GREEN   PORTA.5
    #define PWM_BOOST   PortC.1
    
    DIR LED_GREEN OUT
    DIR PWM_BOOST OUT
    DIR PORTA.0 IN
    
    LED_GREEN=1
    
    'HPWM CCPchannel, frequency, duty cycle
    HPWM 1, 40, 25
    
    do
      LED_GREEN = !LED_GREEN
      wait 100 ms
    loop
    
     

    Last edit: Anobium 2018-04-07
  • Anobium

    Anobium - 2018-04-07

    @Peter. This is something in the config. The default is had been changed from the other K42's.

    Add the following to #enable Clock Switch Enable bit via writing to NOSC and NDIV.

    #config CSWEN = ON   
    

    Does this resolve the issue?

     
  • Peter

    Peter - 2018-04-07

    Hi,
    I compiled your code and problem remains - led flashing once per second and PWM is now 10kHz.

    ps:
    i verified the chip is working correct by using free version of mikroc pro with following code:
    project-settings: 18F47K42 and 16MHz)
    I'm just using the flashing led part and I get 4 blinks per second as expected.

    void main (){
        OSCCON1 = 0x60;
        OSCCON3 = 0x00;
        OSCEN   = 0x00;
        OSCFRQ  = 0x05;
        OSCTUNE = 0x00;
    
        TRISA   = 0x00;
    
       do {
          LATA = 0x30;
          VDelay_ms(125);
          LATA = 0x16;
          VDelay_ms(125);
        } while (1);
    }
    
     
  • Anobium

    Anobium - 2018-04-07

    @Peter. This is something in the config. The default is had been changed from the other K42's.

    Add the following to #enable Clock Switch Enable bit via writing to NOSC and NDIV.

    #config CSWEN = ON

    Does this resolve the issue?

     
  • Peter

    Peter - 2018-04-07

    Hi,
    I'm currently at home and can't check PWM with oscilloscope - but the LED is now flashing as expected.
    Will report back on monday after verifying the PWM-output.

    Thank you very much for figuring this out so quickly.

    Happy weekend :)

     
  • Anobium

    Anobium - 2018-04-07

    Pleasure. The default for the 18f2xK42 was different - Microchip does puzzle me sometimes. I have updated the .dat file in SVN. You do not need to add the config line just grab the lastest .dat file.

     
  • Peter

    Peter - 2018-04-09

    Hi,
    I want to report back now - the updated chipdata-file is working fine (I removed the config option from code using only the updated chipdata-file).
    I just measured PWM-output and this also is working fine now.

    thanks again for your super-fast solution for this

     

Log in to post a comment.