News:

;) This forum is the property of Proton software developers

Main Menu

Using the HPWM command outside the boundaries of osc.

Started by OG, Apr 03, 2021, 12:44 PM

Previous topic - Next topic

OG

First of all, I did the experiment only in ISIS environment.


According to the MCU oscillator status, the minimum hpwm frequency is as follows.
''  Xtal frequency  Lowest useable PWM frequency
''    4MHz              145Hz
''    8MHz              489Hz
''    10MHz            611Hz
''    12MHz            733Hz
''    16MHz            977Hz
''    20MHz            1221Hz
''    24MHz            1465Hz
''    33MHz            2015Hz
''    40MHz            2442Hz

How can it use 246Hz hpwm frequency (mcu 16MHz)?
Things get messed up at lower hpwm values.
Test files are attached.


hpwm.JPG


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

Device = 16F1827

Declare Reminders Off
@ CONFIG_REQ = 0 ; Override Compiler's configuration settings
Asm-
__Config _Config1, 0x091C ;FOSC_INTOSC & WDTE_ON & PWRTE_ON & MCLRE_OFF & CP_ON & CPD_OFF & BOREN_OFF & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF
__Config _Config2, 0x1CFF ;WRT_OFF & PLLEN_OFF & STVREN_OFF & BORV_LO & LVP_OFF
Endasm-
Declare Reminders On

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

Declare Xtal = 16
Declare All_Digital = True
Declare CCP1_Pin PORTB.3
Declare CCP2_Pin PORTA.7
Declare CCP3_Pin PORTA.4
Declare CCP4_Pin PORTA.3

OSCCON = %01111010               ' int osc 16MHz

PORTA = %00000000   
PORTB = %00001000                 
TRISA = %10100111  
TRISB = %11110111  
PORTA = %00000000   
PORTB = %00001000                        


ANSELA = 0               ' DIGITAL
ANSELB = 0

WDTCON = %00011011       ''' <5:1> 01101 = 1:262144 (218) (Interval 8s nominal), <1> =1 WDT on

OPTION_REG = %10001111   
WPUA = 0
WPUB = %00000000        
INTCON = 0

ANSELA = 0
ANSELB = 0

CM1CON0.7 = 0     ''' Comparator is disabled
CM2CON0.7 = 0     ''' Comparator is disabled

CCP1CON = %00001100
'CCP2CON = %00001100
'CCP3CON = %00001100
'CCP4CON = %00001100

Dim pwm_1 As Byte
Dim pwm_2 As Byte
Dim pwm_3 As Byte
Dim pwm_4 As Byte

;;;;;;;;;;;;;

''  Xtal frequency   Lowest useable PWM frequency
''    4MHz              145Hz
''    8MHz              489Hz
''    10MHz             611Hz
''    12MHz             733Hz
''    16MHz             977Hz
''    20MHz             1221Hz
''    24MHz             1465Hz
''    33MHz             2015Hz
''    40MHz             2442Hz

''''''''''''''''
pwm_1 = 127
'pwm_2 = 50
'pwm_3 = 100
'pwm_4 = 254

HPWM 1,pwm_1,246
'HPWM 2,pwm_2,400
'HPWM 3,pwm_3,400
'HPWM 4,pwm_4,400
   
loops:
Clrwdt
GoTo loops


tumbleweed

QuoteAccording to the MCU oscillator status, the minimum hpwm frequency is as follows.
It looks like the entries in that list assume the max TMR prescaler is 1:16
Some devices (like the 16F1827) have a 1:64 prescaler setting, so the min freq is approx 977/4 = 245