Menu

HWPM 18F57Q84 how is it done?

Help
2026-03-26
2 days ago
  • Roger Jönsson

    Roger Jönsson - 2026-03-26

    I tried bunch of stuff for a good while, including some demos and last AI examples. No luck. It's just plain dead. No output on PORTC.2
    The more I read in the docs the more confused I get.
    What is wrong or missing?
    I found PWM11 (18F57Q84) in the PPS tool and tried with that.-Nope. AI suggested PWM1-didn't work.

    #chip 18F57Q84, 64
    #option Explicit
    
        // PIC PPS Tool version: 0.0.6.5
    
        #startup InitPPS, 85
        #define PPSToolPart 18F57Q84
    
        Sub InitPPS
    
                // Module: PWM1_16BIT
                RC2PPS = 0x0018    // PWM11 > RC2
    
            End Sub
        // Add this code segment to your GCBASIC source program
    
    Dir PORTC Out
    
    HPWM 11, 1000, 50, 2 
    
    Do
    Loop
    
     
  • Anobium

    Anobium - 2026-03-27

    Check the Q84 PwM demos.

     
  • Roger Jönsson

    Roger Jönsson - 2026-03-27

    Actually I did yesterday and I didn't even understand how get the fixed mode up and running. What was all that code doing??? And what about "It will emit the signal for 10 seconds, then stop."?? How?? Where?? Turns out that was not true. It does not stop.

    Ok. So I tried again, cleared the weeds and this is the simple code for fixed mode on 18F57Q84:
    Correct? I don't know but it does output 1 MHz on PORTC.2.

    #CHIP 18F57Q84, 64
    #OPTION Explicit
    
        // PIC PPS Tool version: 0.0.6.5
        #startup InitPPS, 85
        #define PPSToolPart 18F57Q84
        //
        Sub InitPPS
                // Module: CCP1
                RC2PPS = 0x0015    // CCP1 > RC2
                CCP1PPS = 0x0012    // RC2 > CCP1 (bi-directional)    
            End Sub
    
    DIR PORTC OUT
    
        #define PWM_Freq 1000    'Set frequency in KHz
        #define PWM_Duty 50    'Set duty cycle to 50 %
    
        'Default to CCP/PWM1
        PWMOn
    
        Do
        Loop
    

    I took the code from here, modified it to suit 18F57Q84 and cleared the stuff not used.
    https://github.com/Anobium/Great-Cow-BASIC-Demonstration-Sources/blob/master/Vendor_Boards/Great_Cow_Basic_Demo_Board/18f27Q84_chiprange_demonstrations/240_pwm_fixed_modes.gcb

     
  • Anobium

    Anobium - 2026-03-27

    Check out the tutorial for PWM for these chips. There are many options and they are explained in tgr video and associated PowerPoint.

     
  • Roger Jönsson

    Roger Jönsson - 2026-03-27

    Trying to output Timer0 at the same time, Both outputs for 4ms, then the both outputs are floating (like inputs) for 4ms and then outputs again . Isn't the PWM using Timer 2? What is this about? What is the conflict?

    #CHIP 18F57Q84, 64
    #OPTION Explicit
    
        // PIC PPS Tool version: 0.0.6.5
        #startup InitPPS, 85
        #define PPSToolPart 18F57Q84
        //
        Sub InitPPS
                // Module: CCP1
                RC2PPS = 0x0015    // CCP1 > RC2
                CCP1PPS = 0x0012    // RC2 > CCP1 (bi-directional)   
                //
                RF3PPS = 0x0039    // TMR0 > RC0  // 28/40-pin PORT B,C / 48-pin PORT C,F (PPS Outputs page 362) 
            End Sub
    
    DIR PORTC OUT
    DIR PORTF OUT
    
     #define PWM_Freq 1000   'Set frequency in KHz
        #define PWM_Duty 50    'Set duty cycle to 50 %
    
        'Default to CCP/PWM1
        PWMOn
    
    InitTimer0 OSC, PRE0_8 + TMR0_HFINTOSC, POST0_1 '64MHz / 8 / 1 
    Settimer (0, 0x80) '/ 128 = 62,5Khz toggled on output pin = 31,25kHz
    StartTimer 0
    
        Do
        Loop
    
     
  • Anobium

    Anobium - 2026-03-27

    Check the ASM.

    Does the PWM work when this is setup ( therefore, no timer0 code )
    Does the timer0 code work when jn PWM code?

    I cannot test at the moment.

     
  • Roger Jönsson

    Roger Jönsson - 2026-03-27

    Both PWM and Timer0 works separately (by commenting out (//) the parts of code).
    When combined the on and off 4ms periods starts.

    If I remove the Timer0 chunk, then The PWM is solid.
    For Timer0 to work then I have to remove both PMWOn and RC2PPS, CCP1PPS from Sub InitPPS = I need to remove both PWMOn and the PPS stuff.

    I tried to have a look in the asm when doing the PWM only, but I did not see Timer0 being involved.
    When running both, Timer0 and Timer2 are in the asm, but I am too bad at asm to understand the conflict or reason for this behaviour. It's like something keeps counting until it flips over. The on/off times are pretty much the same.

     
    • Anobium

      Anobium - 2026-03-27

      Disable the PPS for timer0. If ok. Then, this is probably cross talk - revise your circuit.

       
  • Roger Jönsson

    Roger Jönsson - 2026-03-27

    Would the tutorial for closest to Q84 be this one?
    PT14: PIC18FxxQ24 chip Family - Using the PIC18FxxQ24 with PWM - 6 ways

    What I am looking for in the end of this experimentation, is having a square wave out on a pin, with a frequency of HFINTOSC/4/8 or HFINTOSC/4/10 etc.

    I could use some other source (that is jitter free), but if I want one to be HFINTOSC/4/10, then I guess that I need to go with one the timers (not Timer0 since it already in use).
    Too many options. Always somehting to complain about. :)
    (Maybe I could do it with CLC, but that even further away from what I currently know).

     
  • Roger Jönsson

    Roger Jönsson - 2026-03-27

    Disabling the PPS for timer0 the problem remains (no change).
    If I don't StartTimer 0, then PWM is fine.
    If I StartTimer 0, both outputs starts going on / off (high Z) / on / off (high Z).

    (There is nothing more connected to the 18F57Q84 curiosity board than USB supply and oscilloscope. The only pins sensitive to touch are the outputs when they go into high Z state)

     
  • Roger Jönsson

    Roger Jönsson - 2026-03-27

    The whole 18F57Q84 seems to reset or something(?).
    If add turning A.6 on, then it too starts going: on / off (high Z) / on / off (high Z)

    I am not doing anything on PORTA other than that.
    Just:
    DIR PORTA OUT
    PORTA.6=1

    If found that out when trying #config CLKOUTEN = ON (or OFF) to see if I could see what happened to Fosc. That didn't work, no clock on A.6, but if I set it on, then I could see that it would not stay high.

     
  • Roger Jönsson

    Roger Jönsson - 2026-03-27

    In the curiosityboard one needs to cut tracks to a crystal in order to use RA6 and 7 as ports. I did that earlier today. Now looking in a microscope, there was a extremely thin trace left. That is why I did not get any Fosc out of RA6.
    Strangely enough, when RA6 was freed, then the toggling of the other ports stopped! How can the crystal on RA6 and RA7 have anything to do with this???
    Still not convinced I have power toggled several times. Yes the outputs just keeps going without interruptions. What may the explanation be?

     

    Last edit: Roger Jönsson 2026-03-27
  • Roger Jönsson

    Roger Jönsson - 2 days ago

    There may be a hardware issue with the 18F57Q84.

    When changing to another 18F57Q84 curiosity board the outputs just dies when I try to output both Timer0 and PWM at the same time. On their own they each work as expected.
    On one board it works very slightly. -Ports are toggling on and off, so it seems like a border case.

    While experimenting getting Timer2+PWM and Timer4+PWM setup in assembler, I got it working on FOSC/4. I then found that it would neither run on HFINTOSC nor MFINTOSC. If I ran the 18F57Q84 at 48MHz or 16MHz then PWM with MFINTOSC as source would work, but not at 64 and 32MHz and never with HFINTOSC.
    I tried fiddling with pauses in code, code order and other stuff, PLL and settings, forcing MFINTOSC etc. No go.
    I can't find anything explaining this in the 18F57Q84 errata.
    Any ideas?

    Edit: The PWM probably needs four cycles to build the Duty Cycle. When using HFINTOSC for the Timer, there is no such 4 x overhead for the PWM. Therefor it fails(?).

     

    Last edit: Roger Jönsson 1 day ago

Log in to post a comment.

MongoDB Logo MongoDB