News:

;) This forum is the property of Proton software developers

Main Menu

HPWM NOT working

Started by Colin G3YHV, May 14, 2022, 08:24 AM

Previous topic - Next topic

Colin G3YHV

Hi- I am using a 18F26K22 and cannot make HPWM command work correctly
I have used it before without  problems and wonder if something has changed ?
I can get a waveform from the pin ok but cannot then change the Mark Space ratio
the following does not work -  the HPWM frequency is correct at 30 kHz

simplified  example below
Colin G3YHV

Device = 18F26K22
Declare Xtal = 64

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 = OFF   ;Power up timer disabled
  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 = 1   ;1:1
  CCP2MX = PORTC1   ;CCP2 input/output is multiplexed with RC1
  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 = On   ;HFINTOSC output and ready status are not delayed by the oscillator stable status
  T3CMX = PORTC0   ;T3CKI is on RC0
  P2BMX = PORTC0   ;P2B is on RC0
  MCLRE = INTMCLR   ;RE3 input pin enabled; MCLR 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-003FFFh) not code-protected
  CP1 = OFF   ;Block 1 (004000-007FFFh) not code-protected
  CP2 = OFF   ;Block 2 (008000-00BFFFh) not code-protected
  CP3 = OFF   ;Block 3 (00C000-00FFFFh) not code-protected
  CPB = OFF   ;Boot block (000000-0007FFh) not code-protected
  CPD = OFF   ;Data EEPROM not code-protected
  WRT0 = OFF   ;Block 0 (000800-003FFFh) not write-protected
  WRT1 = OFF   ;Block 1 (004000-007FFFh) not write-protected
  WRT2 = OFF   ;Block 2 (008000-00BFFFh) not write-protected
  WRT3 = OFF   ;Block 3 (00C000-00FFFFh) 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-003FFFh) not protected from table reads executed in other blocks
  EBTR1 = OFF   ;Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
  EBTR2 = OFF   ;Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
  EBTR3 = OFF   ;Block 3 (00C000-00FFFFh) 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 ****


OSCCON=%01110000                   ' 16MHz intosc
OSCTUNEbits_PLLEN = 1 ;Enable PLL
 DelayMS 50   ;After writing these registers the oscillator becomes unstable for a while
 Dim n As Byte
 
  For n= 1 To 5               '  test led -  flashes ok
  High PORTB.7
  DelayMS 100
  Low PORTB.7
  DelayMS 100
  Next


 For n= 1 To 10    'The led slowly flashes but HPWM mark/space  ratio remains at about 50:50
 High PORTB.7 ' test led
 
 HPWM 1,5,30000
 DelayMS 1000
 HPWM 1,128,30000
 DelayMS 1000
 HPWM 1,2,30000
 
 Low PORTB.7 ' test led
 DelayMS 1000
 Next n

End



diebobo

Try use Declare Optimiser_Level = 0 in your code on top.. I ran into this isue this morning to and am investigating now.. Seems somewhere between version 3.7.3.6 and 4.0.0.6 a Optimiser level 5 is auto applied to HWPWM command, even if it isn't used as a declare..

Colin G3YHV

Thanks for the quick replay -  I will try that later today.
Just off to a garden centre  -  slugs have eaten my courgettes!
Colin

Colin G3YHV

Tried  Declare Optimiser_Level = 0
still does not work !
Colin

Colin G3YHV

Oh I forgot to mention I am using Positron ver 4.0.1.6
Colin

diebobo

Oh, that's to bad.. Then i am affraid i can't help you. I hoped it was the same problem as with me, i'll open another topic for that one..

In the meanwhile, you might install a previous version which was working for you. Save the .lst and .asm file. Install the new compiler and do the same. Compare then on the interwebs ( google difchecker ) and see if u are able to identify the problem.. And report back here :)..

top204

I have tried the HPWM commands on a PIC18F26K22 using the latest Positron compiler, and they work as expected. The latest Positron8 compiler version is version 4.0.1.7, available from here: Positron Corrections Update 4.0.1.7 - 1.1.0.8, since April 2022.

Below is the simple program I wrote for the test:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' A test of the HPWM commands on a PIC18F26K22 device.
' Create a PWM wave of 2000 Hz at 50% duty cycle from pins CCP1 and CCP2.
'
' Written by Les Johnson for the Positron8 compiler, version 4.0.1.7 onwards.
'
    Device = 18F26K22
    Declare Xtal = 16                         
'
' Setup the pins for HPWM
'
    Declare CCP1_Pin = PORTC.2      ' The pin used for CCP1
    Declare CCP2_Pin = PORTC.1      ' The pin used for CCP2
 
'------------------------------------------------------------------------
' The main program starts here
'
Main:
    HPWM 1, 127, 2000               ' Start a PWM waveform from CCP1
    HPWM 2, 127, 2000               ' Start a PWM waveform from CCP2

I tried the above code on a real device and it worked. I ran it in a simulator so I could take a screenshot and it also worked, as shown below:
18F26K22_HPWM.jpg

Colin G3YHV

Thanks for that Les. I have found the problem was a wiring error !
The supply to the chip was missing- but it still worked ( sort of!)
Even my test led flashed. The chip was running through some tie up resistors
via a strange route  through the chip!
I have also updated to the latest version -  should have gone to specsavers
Regards Colin