News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Hi, whats wrong here? (18F25K22 pwm)

Started by Maxi, Mar 08, 2021, 08:38 AM

Previous topic - Next topic

Maxi

if I select 18F26K22 no problem.
when compile 18F25K22 give asm error.
*compiler version is 3.7.5.5

Device 18F25K22
Declare Xtal=8

Declare CCP2_Pin PORTC.1

AAA:
HPWM 2,127,1000

GoTo AAA

top204

This was discussed a few weeks back here on the forum.

Open the P18F25K22.PPI file, located at: C:\Program Files (x86)\Positron Compilers\PDS\Includes\PPI\

And alter the line:
HPWM=4              ; Amount of PWM channels (supported by the compiler) available

to

HPWM=2              ; Amount of PWM channels (supported by the compiler) available

Important Note Only open the .PPI file with NotePad, otherwise, word processors place hidden character controls in the text and make it not readable by the compiler's parser.

The next update corrects the PPI and and I have created a library subroutine for the PIC18F25K22 and PIC18F45K22 devices that give them support for 5 PWM channels with the HPWM command.

okaman

Quote from: top204 on Mar 08, 2021, 05:51 PMThis was discussed a few weeks back here on the forum.

Open the P18F25K22.PPI file, located at: C:\Program Files (x86)\Positron Compilers\PDS\Includes\PPI\

And alter the line:
HPWM=4              ; Amount of PWM channels (supported by the compiler) available

to

HPWM=2              ; Amount of PWM channels (supported by the compiler) available

Important Note Only open the .PPI file with NotePad, otherwise, word processors place hidden character controls in the text and make it not readable by the compiler's parser.

The next update corrects the PPI and and I have created a library subroutine for the PIC18F25K22 and PIC18F45K22 devices that give them support for 5 PWM channels with the HPWM command.

i liked this news so much ,becaouse i will request also for pic16f1527 5pwm channel output (min 2 pwm channel wil run in the same time with HPWM command indepented frequency and duty )
is it possible?

I have created a library subroutine for the PIC18F25K22 and PIC18F45K22 devices that give them support for 5 PWM channels with the HPWM command.
DWIN Sale Manager TURKEY
(info@kamantek.com)
http://www.kamantek.com/shop/index.php

joesaliba

Quote from: top204 on Mar 08, 2021, 05:51 PMThe next update corrects the PPI and and I have created a library subroutine for the PIC18F25K22 and PIC18F45K22 devices that give them support for 5 PWM channels with the HPWM command.

Les,

Very long time ago the compiler did had support for 5 PWM on these devices, (it was 18F26K22 which is same as 18F25K22 but 5v). I have a project running with 5 PWM, but to be honest I never compiled again so cannot say what changed.

Regards

Joseph

top204

#4
The new library subroutine will also work with the 18Fx6K22 devices and other 18F types, but I will need to test them individually for Asm errors, because I do not physically have all devices.

I was expanding the channels for the HPWM command that use the CCP peripherals, but then Microchip started changing how they work on various device families, but not documenting what changes were required, or even if changes were required, so I had to move them down to two channels, just in case the changes were not obvious and they didn't work. I couldn't afford to buy every single PIC device available to test, and I got no help from the company with devices, and I didn't have the time to go through every device I could afford for testing because I created the compilers at home in the evenings and weekends (my time), so I had to play it safe with the code and go to 2 channels.

If time, and funding, permits, I will go through some of the enhanced 14-bit core devices and see about expanding their channels. But also making them work with different timers in the library subroutine is something that I think is an over-kill for a built in command. For that sort of functionality, it requires a library of procedures created by a user who is working on a particular device's functionality that will choose the timer and the CCP from parameters etc... Then upload the library they have created to the forum's Wiki, which will make it more suitable for future devices because the code will be alterable so users of the compiler can change it for a particular device that has differences, or create a new library for a device that does things differently.


Maxi

Thank you, 18F25K22 working well now.

xldaedalus

#6
For those interested, the HPWM set up included with the compiler, more or less automatically configures the two CCP PWM modules.  The 18F2xK22 has 3 ECCP PWM modules.  These are more complicated because they can do much more, like make Half Bridge motor drivers.  Many of the other PIC 18F chips have ECCP modules, so it's a good idea to learn how to use them.

I'm been using the ECCP PWM modules on the 18F26k22 for years, and have been incorporated into > 10,000 products.  I love them.

You can find Step by step instructions for setting up and using the ECCP modules in the 18F2xK22 in the data sheet are found here:

14.4.8 SETUP FOR ECCP PWM OPERATION USING ECCP1 AND TIMER2
Never, never, never give up

flosigud

The code below used to work for me to set all five PWM channels on 18f2xk22:

;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings

Device = 18F25K22

Config_Start
  FOSC = INTIO67 ;Internal oscillator block
  PLLCFG = On ;Oscillator multiplied by 4
  PRICLKEN = On ;Primary clock enabled
  FCMEN = OFF ;Fail-Safe Clock Monitor disabled
  IESO = OFF ;Oscillator Switchover mode disabled
  PWRTEN = On ;Power up timer enabled
  BOREN = SBORDIS ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
  BORV = 190 ;VBOR set to 1.90 V nominal
  WDTEN = OFF ;Watch dog timer is always disabled. SWDTEN has no effect.
  WDTPS = 32768 ;1:32768
  CCP2MX = PORTB3 ;CCP2 input/output is multiplexed with RB3
  PBADEN = OFF ;PORTB<5:0> pins are configured as digital I/O on Reset
  CCP3MX = PORTB5 ;P3A/CCP3 input/output is multiplexed with RB5
  HFOFST = OFF ;HFINTOSC output and ready status are delayed by the oscillator stable status
  T3CMX = PORTB5 ;T3CKI is on RB5
  P2BMX = PORTC0 ;P2B is on RC0
  MCLRE = EXTMCLR ;MCLR pin enabled, RE3 input pin disabled
  STVREN = On ;Stack full/underflow will cause Reset
  LVP = OFF ;Single-Supply ICSP disabled
  XINST = OFF ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
  Debug = OFF ;Disabled
  Cp0 = OFF ;Block 0 (000800-001FFFh) not code-protected
  CP1 = OFF ;Block 1 (002000-003FFFh) not code-protected
  CP2 = OFF ;Block 2 (004000-005FFFh) not code-protected
  CP3 = OFF ;Block 3 (006000-007FFFh) not code-protected
  CPB = OFF ;Boot block (000000-0007FFh) not code-protected
  CPD = OFF ;Data EEPROM not code-protected
  WRT0 = OFF ;Block 0 (000800-001FFFh) not write-protected
  WRT1 = OFF ;Block 1 (002000-003FFFh) not write-protected
  WRT2 = OFF ;Block 2 (004000-005FFFh) not write-protected
  WRT3 = OFF ;Block 3 (006000-007FFFh) not write-protected
  WRTC = OFF ;Configuration registers (300000-3000FFh) not write-protected
  WRTB = OFF ;Boot Block (000000-0007FFh) not write-protected
  WRTD = OFF ;Data EEPROM not write-protected
  EBTR0 = OFF ;Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
  EBTR1 = OFF ;Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
  EBTR2 = OFF ;Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
  EBTR3 = OFF ;Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
  EBTRB = OFF ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------


        Declare All_Digital 1
Declare Xtal =64

        Declare Optimiser_Level 3
        Declare Dead_Code_Remove = On

Symbol PLLEN = OSCTUNE.6 ' PLL enable
Symbol HFIOFS = OSCCON.2  ' HFINTOSC frequency stable
Symbol PLLRDY = OSCCON2.7 ' PLL run status

Dim DUTY1 As Word
Dim DUTY2 As Word
Dim DUTY3 As Word
Dim DUTY4 As Word
Dim DUTY5 As Word

        OSCCON=%01110000                   ' 16MHz intosc
        'OSCCON=%01100000                   ' 8MHz intosc
'OSCCON=%01010000                   ' 4MHz intosc
        'OSCCON=%01000000                   ' 2MHz intosc
        'OSCCON=%00110000                   ' 1MHz intosc

        PLLEN=1 ' PLL on

        While HFIOFS=0:Wend                ' Wait until osc is stable
'        While PLLRDY=0:Wend ' Wait until PLL is stable

CCPTMRS0 =%00000000 ' Use Timer2 for all
CCPTMRS1 =%00000000

TRISB=0
DUTY1=300
DUTY2=400
DUTY3=500
DUTY4=600
DUTY5=700
         
'T2CON = %00000100 ' Precaler 1:1
'2CON = %00000101 ' Precaler 1:4
T2CON = %00000111 ' Precaler 1:16
PR2 = 249

Output PORTC.2
Output PORTB.3
        Output PORTB.5
Output PORTB.0
Output PORTA.4

CCP1CON = %00001100                 ' PWM mode
CCP1CON.4 = DUTY1.0 ' Store duty to registers as
CCP1CON.5 = DUTY1.1 ' a 10-bit word
CCPR1L = DUTY1 >> 2

CCP2CON = %00001100                 ' PWM mode
CCP2CON.4 = DUTY2.0 ' Store duty to registers as
CCP2CON.5 = DUTY2.1 ' a 10-bit word
CCPR2L = DUTY2 >> 2          

CCP3CON = %00001100                 ' PWM mode
CCP3CON.4 = DUTY3.0 ' Store duty to registers as
CCP3CON.5 = DUTY3.1 ' a 10-bit word
CCPR3L = DUTY3 >> 2          

CCP4CON = %00001100                 ' PWM mode
CCP4CON.4 = DUTY4.0 ' Store duty to registers as
CCP4CON.5 = DUTY4.1 ' a 10-bit word
CCPR4L = DUTY4 >> 2          

CCP5CON = %00001100                 ' PWM mode
CCP5CON.4 = DUTY5.0 ' Store duty to registers as
CCP5CON.5 = DUTY5.1 ' a 10-bit word
CCPR5L = DUTY5 >> 2
   
' While 1=1:Wend
Stop


And here is another slightly faster way of moving 10 bits to its destination:


Include "18f25k22intosc11520064.inc"

CCPTMRS0 =%00000000 '
CCPTMRS1 =%00000000

TRISA = 0
TRISB = 0
TRISC = 0
       
'T2CON = %00000100 ' Precaler 1:1
'T2CON = %00000101 ' Precaler 1:4
T2CON = %00000111 ' Precaler 1:16
PR2 = 249

'T4CON = %00000100 ' Precaler 1:1
'T4CON = %00000101 ' Precaler 1:4
T4CON = %00000111 ' Precaler 1:16
PR4 = 249

'T6CON = %00000100 ' Precaler 1:1
T6CON = %00000101 ' Precaler 1:4
'T6CON = %00000111 ' Precaler 1:16
PR6 = 249

$define CopyBits(bitmask,from_file,to_file)  '
    WREG = to_file ^ from_file                '
    WREG = WREG & bitmask                    '   
    to_file = to_file ^ WREG

$define SetDuty1(SD) '
Swapf SD.LowByte,WREG '
CopyBits($30,WREG,CCP1CON) '
CCPR1L = SD >> 2

$define SetDuty2(SD) '
Swapf SD.LowByte,WREG '
CopyBits($30,WREG,CCP2CON) '
CCPR2L = SD >> 2

$define SetDuty3(SD) '
Swapf SD.LowByte,WREG '
CopyBits($30,WREG,CCP3CON) '
CCPR3L = SD >> 2

$define SetDuty4(SD) '
Swapf SD.LowByte,WREG '
CopyBits($30,WREG,CCP4CON) '
CCPR4L = SD >> 2

$define SetDuty5(SD) '
Swapf SD.LowByte,WREG '
CopyBits($30,WREG,CCP5CON) '
CCPR5L = SD >> 2

$define PWMON1() CCP1CON = CCP1CON | $0C
$define PWMON2() CCP2CON = CCP2CON | $0C
$define PWMON3() CCP3CON = CCP3CON | $0C
$define PWMON4() CCP4CON = CCP4CON | $0C
$define PWMON5() CCP5CON = CCP5CON | $0C

$define PWMOFF1() CCP1CON = CCP1CON & $F3
$define PWMOFF2() CCP2CON = CCP2CON & $F3
$define PWMOFF3() CCP3CON = CCP3CON & $F3
$define PWMOFF4() CCP4CON = CCP4CON & $F3
$define PWMOFF5() CCP5CON = CCP5CON & $F3

Dim DUTY1 As Word
Dim DUTY2 As Word
Dim DUTY3 As Word
Dim DUTY4 As Word
Dim DUTY5 As Word

DUTY1=100
DUTY2=200
DUTY3=300
DUTY4=400
DUTY5=500

PWMON1()
SetDuty1(800) ' PortC.2

PWMON2()
SetDuty2(DUTY2) ' PortB.3

PWMON3()
SetDuty3(DUTY3) ' PortB.5

PWMON4()
SetDuty4(DUTY4) ' PortB.0

PWMON5()
SetDuty5(DUTY5) ' PortA.4

Stop

top204

I really like your CopyBits meta-macro. :-)

An excellent understanding of Boolean and the compiler's mechanisms.

flosigud

CopyBits is just a trick I learned during my early and short Z80 days. I later googled how to do this in PIC assembler and converted to Proton. The funny thing is that the assembler produced is the same. In the example above it compiles to only three program words as from_file is already in WREG.