News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Can't get HPWM5 working on Proteus

Started by Yves, Mar 18, 2024, 11:22 AM

Previous topic - Next topic

Yves

Hello all,
I'm using a PIC18F26k22 with internal clock running at 64mHz. I have also tried without PLL at 16mHz. At the moment I'm doing Proteus 8. I can't get HPWM running. The LED is blinking alright. Where am I going wrong Below the snippet:

Symbol LED = PORTB.5 :Output PORTB.5 'pin 26

Declare HPWM1_Pin = PORTA.4 ' Select HPWM port and bit for PWM 5 module (ch 5)
HPWM 5, 50, 4000

While 1=1
    Toggle LED
    DelayMS 50
Wend

Using Positron 4.0.4.0 version

Regards,

Yves






Yves

Dompie

I don't know but on page 2 of the datasheet:
• Four 10-bit Pulse-Width Modulators (PWMs)

Johan

top204

#2
I've just tried it in Positron8 version 4.0.4.0 and the HPWM command is working.

I used the program listing below:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Test the HPWM commands on a PIC18F26K22 device
'
' Written by Les Johnson for the Positron8 compiler.
'
    Device = 18F26K22                                   ' Tell the compiler what device to compile for
    Declare Xtal = 16                                   ' Tell the compiler what frequency the device will be operating at (in MHz)
'
' Setup the CCP pins for the HPWM command (Can also be named: "CCPx_Pin = Port.Pin"
'
    Declare HPWM1_Pin = PORTC.2
    Declare HPWM2_Pin = PORTC.1
    Declare HPWM3_Pin = PORTB.5
    Declare HPWM4_Pin = PORTB.0
    Declare HPWM5_Pin = PORTA.4

'-------------------------------------------------------------------------------------------
' The main program starts here
'
Main:
    HPWM 1, 127, 2000
    HPWM 2, 127, 2000
    HPWM 3, 127, 2000
    HPWM 4, 127, 2000
    HPWM 5, 127, 2000

I do seem to remember an anomaly in the proteus simulator a few months back with PWM on some devices, where it worked on a real device but not in the simulator when using the higher PWM channels on their own. Below is a screenshot of the above program listing running in the Proteus simulator on a PIC18F26K22 model:

HPWM_18F26K22.jpg

Yves

Thank you less,

your code worked perfectly. Must have been something wrong with my fuse configuration when I removed it the code worked well. The snippet I publish initially had a typo error but when I corrected it wasn't working that point to my fuse configuration.

Kind regards,

Yves
Yves

Yves

No i'm confused Why this below doesn't work:
   Device = 18F26K22                                   ' Tell the compiler what device to compile for
    Declare Xtal = 16                                   ' Tell the compiler what frequency the device will be operating at (in MHz)
'
' Setup the CCP pins for the HPWM command (Can also be named: "CCPx_Pin = Port.Pin"
'
'    Declare HPWM1_Pin = PORTC.2
'    Declare HPWM2_Pin = PORTC.1
 '   Declare HPWM3_Pin = PORTB.5
 '   Declare HPWM4_Pin = PORTB.0
    Declare HPWM5_Pin = PORTA.4

'-------------------------------------------------------------------------------------------
' The main program starts here
'
Main:
'    HPWM 1, 127, 2000
'    HPWM 2, 127, 2000
'    HPWM 3, 127, 2000
'    HPWM 4, 127, 2000
    HPWM 5, 127, 2000

Is some CCP are interconnected?
Yves
Yves

Yves

It only works as below:

'    Declare HPWM1_Pin = PORTC.2
'    Declare HPWM2_Pin = PORTC.1
Declare HPWM3_Pin = PORTB.5
 '   Declare HPWM4_Pin = PORTB.0
Declare HPWM5_Pin = PORTA.4

'-------------------------------------------------------------------------------------------
' The main program starts here
'
Main:
'    HPWM 1, 127, 2000
'    HPWM 2, 127, 2000
HPWM 3, 50, 2000
'    HPWM 4, 127, 2000
HPWM 5, 50, 2000

Now it is getting even more confusing. To change the duty I have to change it on the HPWM 3(CCP3). Though  port for HPWM has no pulse. All I need is HPW5 on CCP5 to work. my head is spinning? I really like to know why.
Yves
Yves

Yves

Is any one can explain why I have to use HPWM 3 to control HPWM 5 using 18F26k22. I have attached the code and Proteus 8.0

Yves
Yves

tumbleweed

There are 5 CCP peripherals that can do PWM, but there are only 3 timers available (TMR2/4/6) so they aren't all independent... some of the CCP peripherals will have to share a TMR.


Yves

@ tumbleweed,
Thank you that now makes sense. I couldn't find a clearer explanation on the specsheet or at least an easy explanation. It was important for me to use PortA.5 as it was the only available pin for this purpose let left on my project which has already have a printed circuit done.

Regards,

Yves   
Yves