PIC 18F1330 HPWM problem - Page 3


+ Reply to Thread
Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 48

Thread: PIC 18F1330 HPWM problem53 days old

  1. #31
    Junior Member capitainehaddock's Avatar
    Join Date
    Oct 2019
    Posts
    26
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    87.74 MB

    0 Not allowed!

    Default Re: Proton PC PWM library for devices 18F1230, 18F1330, 18F2331, 18F2431, 18F4331, 18

    Thanks Les
    i will revert to 18F1330,
    will try and let you know
    best regards
    Archi

Attention

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #32
    Junior Member capitainehaddock's Avatar
    Join Date
    Oct 2019
    Posts
    26
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    87.74 MB

    0 Not allowed!

    Default Re: Proton PC PWM library for devices 18F1230, 18F1330, 18F2331, 18F2431, 18F4331, 18

    Hi Les
    i tested your file PCPWM_Test.bas with the new PCPWM.inc .
    After compilation and simulation, IT WORKS.
    After a LPF, i obtain a ramp 0 to 1.25V on PWM 1 and 3,
    and a ramp 5V to 3.75V on PW0 and PWM2.

    I dont manage yet to adapt this to my own code, to make the necessary actions.
    (i am not an "expert").

    best regards
    Archi

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #33
    Junior Member capitainehaddock's Avatar
    Join Date
    Oct 2019
    Posts
    26
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    87.74 MB

    0 Not allowed!

    Default Re: Proton PC PWM library for devices 18F1230, 18F1330, 18F2331, 18F2431, 18F4331, 18

    Hi Les
    i never managed to use what you sent to do what i wanted to do
    Nevertheless, thanks for what you do.
    I reverted my project to 16F1827, and it works.
    only improvement i have to manage is to have PWM in 10 bit instead of 8
    but this is out of subject about 18F1330 posts.

    Best regards
    Archi

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #34
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,468
    Thumbs Up
    Received: 71
    Given: 29
    Total Downloaded
    6.17 GB

    0 Not allowed!

    Default Re: PIC 18F1330 HPWM problem

    Archi,

    Have a look at this old code I used to use for 10 bit HPWM.

    Note that I use a first time HPWM because it seems that frequency is set as desired. I had checked it on an osciloscope. Then I only alter the registers to have the 10 bit pulse width.

    Code:
    Device = 16F877
    
    Xtal = 8
    
    Declare LCD_Type 0
    Declare LCD_DTPin PORTD.4
    Declare LCD_ENPin PORTD.3
    Declare LCD_RSPin PORTD.2
    Declare LCD_Interface 4
    Declare LCD_Lines 2
    
    Dim PW      As Word
    Dim Freq    As Word
    Dim Temp_PW As Word
    '________________________________________________________________________________________
    
    Symbol Dwn = PORTB.0
    Symbol Up  = PORTB.1
    '________________________________________________________________________________________
    
    
    TRISA  = %00000000          ' Configure PORTA as output
    TRISB  = %11111111          ' Configure PORTB as input
    TRISC  = %00000000          ' Configure PORTC as input
    TRISD  = %00000000          ' Configure PORTD as output
    TRISE  = %00000000          ' Configure PORTE as output
    ADCON1 = %10000110          ' PORTA and PORTE as digital I/O
    '________________________________________________________________________________________
    
    CCP1_Pin = PORTC.2          ' PORTC.2 is the CCP1 pin on the 16F877 device
    
    Low PORTA
    Low PORTC
    Low PORTD
    Low PORTE
    '________________________________________________________________________________________
    
    Cls
    PW = 1                      ' Load PW with value 1
    Freq = 2000                 ' Load Freq with value 2000
    Temp_PW = PW                ' Copy PW to variable Temp_PW
    
    HPWM 1,PW,2000              ' Send a duty cycle signal at 2.0KHz
    '========================================================================================
    
    Main:
    CCP1CON.4 = Temp_PW.0       ' Place bit-0 of the duty in the LSB register (bit-4)
    CCP1CON.5 = Temp_PW.1       ' Place bit-1 of the duty in the LSB register (bit-5)
    
    Temp_PW = Temp_PW>>2        ' Shift the duty cycle value down two places
    
    CCPR1L = Temp_PW            ' Load the MSB of the 10-bit duty value
    
    Print At 1,1, @PW,"  "      ' Display the PW value
    Print At 2,1, @Freq,"  "    ' display the frequency
    
    If Up = 0 Then DelayMS 100 : Inc PW ' Use an osciloscope to see cahnges when button is pressed
    If PW > 1023 Then PW = 1023         ' Limit upper value to 1023
    
    
    If PORTB.3 = 0 Then PW = 512  If Dwn = 0 Then DelayMS 100 : Dec PW ' Use an osciloscope to see cahnges when button is pressed
    If PW < 1 Then PW = 1                ' Limit the lowest value to 1
    
    If PORTB.2 = 0 Then PW = 1023
    If PORTB.4 = 0 Then PW = 1
    
    Temp_PW = PW                ' Re-load Temp_Pw with Pw
    
    GoTo Main                   ' Do it forever
    
    '========================================================================================
    Regards

    Joseph

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #35
    Junior Member capitainehaddock's Avatar
    Join Date
    Oct 2019
    Posts
    26
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    87.74 MB

    0 Not allowed!

    Default Re: PIC 18F1330 HPWM problem

    Hi Thanks
    What i wrote is attached.
    I am still searching to have 10 bit PWMs working.
    For now i am making simulations with proteus,
    The 2 separate 8 bit PWMs are working well.
    I will receive PCB & components next week
    to test in true life, and see....

    Best regards
    Archi

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;
    Device = 16F1827


    Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_OFF, MCLRE_ON, CP_OFF, CPD_OFF, BOREN_OFF, CLKOUTEN_OFF, IESO_OFF, FCMEN_OFF
    Config2 WRT_OFF, PLLEN_ON, STVREN_OFF, LVP_ON


    Declare Xtal = 32


    ; bits 76543210
    OSCCON = %11110010 ; (Page 65 of DataSheet) Set HFIntosc at 32 Mhz
    T1CON = %01000101 ; (Page 185) Timer 1 active as system clock (Fosc)
    T2CON = %00000100 ; (Page 191) Timer 2 active for PWM1
    T4CON = %00000100 ; (Page 191) Timer 4 active for PWM2
    TRISA = %01111111 ; (Page 122) Port A7 as output, others as inputs (1= Input, 0= Output)
    ANSELA = %00001111 ; (Page 123) Ports A0 to A3 analogic inputs (1 = Ana, 0 = Digital)
    TRISB = %01110111 ; (Page 127) Ports B3 et B7 as outputs (1 = Input, 0 = Output)
    ANSELB = %00000000 ; (Page 128) No Analogic affectations in Ports B, All Digital
    ADCON0 = %00001011 ; (Page 145) ADC AN2 Enabled
    ADCON1 = %11110000 ; (Page 146) AD format right justified, VREF+ = VDD & VREF- = VSS
    CCP1CON = %00111100 ; (Page 226) Single output PWM1. bit 5-4: 11 for 10 bit PWM ??
    CCP2CON = %00111100 ; (Page 226) Single Output PWM2. bit 5-4: 11 For 10 bit PWM ??
    CCPTMRS = %11110100 ; (Page 227) CCP1 as PWM1 on Timer2 & CCP2 as PWM2 on Timer4
    APFCON0 = %00001000 ; (Page 119) CCP1/P1A/PWM1 in Port B3 , CCP2/P2A/PWM2 in Port A7
    PWM1CON = %10000000 ; (Page 229) PWM delay count 0
    PWM2CON = %10000000 ; (Page 229) PWM delay count 0
    PIE1 = %11110111 ; (Page 87) Enables necessary interrupts
    PIE2 = %11110001 ; (Page 88) Enables necessary interrupts
    PIE3 = %00000010 ; (Page 89) Enables necessary interrupts
    PIE4 = %00000000 ; (Page 90) Enables necessary interrupts

    Declare Serial_Baud 19200
    Declare Rsin_Pin PORTB.6 ; For Pickit3
    Declare Rsin_Mode 1 ; Inverted
    Declare Rsout_Pin PORTB.7 ; For Pickit3
    Declare Rsout_Mode 0 ; Non inverted, as inversion is made by Q1 (2N7000)
    Declare CCP1_Pin PORTB.3 ; Enhanced PWM1 output Max 31.2 kHz @ 10 Bit, 125 kHz @ 8 bit !
    Declare CCP2_Pin PORTA.7 ; Enhanced PWM2 output Max 31.2 kHz @ 10 Bit, 125 kHz @ 8 Bit !
    Declare PortB_Pullups = 1 ; Pull up on ports B
    Declare Adin_Res = 10 ; ADC 10 bit result required (0 to 1023)
    Declare Adin_Tad = FRC ; Internal HF OSC chosen for ADC timer
    Declare Adin_Stime = 50 ; Allow 50 us sample time

    Dim i As Byte ; For sub routine Read_PWR (0 to 255)
    Dim i_1 As Byte ; For sub routine Read_SWR (0 to 255)
    Dim V_FWD_1 As Word ; i x 10 bit ADC result (0 to 1023) stored in 16 Bit (0 To 65535)
    Dim V_FWD As Float ; Mean value 32 bit floating point on i mesures in volts
    Dim Calcul_PWR_a As Float ; Intermediate calculation (3 operations max by line)
    Dim Calcul_PWR As Float ; Calculation result used by PWM for output 0 to 5 V
    ;Dim PWR_Lin As byte ; For PWM 8 bit 5 V = 100% = 255 for output 0 to 5 V
    Dim PWR_Lin As Word ; For PWM 10 Bit 5 V = 100%. To be limited to 1023 For output 0 to 5 V
    Dim V_REF_1 As Word ; i x 10 bit ADC result (0 to 1023) stored in 16 bit (0 to 65535)
    Dim V_REF As Float ; Mean value 32 bit floating point on i_1 mesures in volts
    Dim Calcul_ROS_a As Float ; Intermediate calculation (3 operations max by line)
    Dim Calcul_ROS As Float ; SWR calculation: SWR 1/1 = 0.5 V , SWR 10/1 = 5 V
    ;Dim SWR_Lin As Byte ; For PWM 8 bit 5 V = 100% = 255 for output 0 to 5 V
    Dim SWR_Lin As Word ; For PWM 10 bit 5 V = 100%. To be limited to 1023 for output 0 to 5 V

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

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #36
    Junior Member capitainehaddock's Avatar
    Join Date
    Oct 2019
    Posts
    26
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    87.74 MB

    0 Not allowed!

    Default Re: PIC 18F1330 HPWM problem

    Hello
    i found a Microchip explanation https://microchipdeveloper.com/8bit:10bitpwm
    accordingly i defined PRx i dont used before and change PWM frequency

    nevertheless still not working in simulation

    attached modified code

    any idea to have it working 10 bits welcomed
    Best regards
    archi


    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;
    Device = 16F1847


    Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_OFF, MCLRE_ON, CP_OFF, CPD_OFF, BOREN_OFF, CLKOUTEN_OFF, IESO_OFF, FCMEN_OFF
    Config2 WRT_OFF, PLLEN_ON, STVREN_OFF, LVP_ON


    Declare Xtal = 16


    ; bits 76543210
    OSCCON = %11111010 ; (Page 65 of DataSheet) Set HFIntosc at 16 Mhz
    ;OSCCON = %11110010 ; (Page 65 of DataSheet) Set HFIntosc at 32 Mhz
    T1CON = %01000101 ; (Page 185) Timer 1 active as system clock (Fosc)
    T2CON = %00000100 ; (Page 191) Timer 2 active for PWM1
    T4CON = %00000100 ; (Page 191) Timer 4 active for PWM2
    TRISA = %01111111 ; (Page 122) Port A7 as output, others as inputs (1= Input, 0= Output)
    ANSELA = %00001111 ; (Page 123) Ports A0 to A3 analogic inputs (1 = Ana, 0 = Digital)
    TRISB = %01110111 ; (Page 127) Ports B3 et B7 as outputs (1 = Input, 0 = Output)
    ANSELB = %00000000 ; (Page 128) No Analogic affectations in Ports B, All Digital
    ADCON0 = %00001011 ; (Page 145) ADC AN2 Enabled
    ADCON1 = %11110000 ; (Page 146) AD format right justified, VREF+ = VDD & VREF- = VSS
    CCP1CON = %00111100 ; (Page 226) Single output PWM1. bit 5-4: 11 for 10 bit PWM ??
    CCP2CON = %00111100 ; (Page 226) Single Output PWM2. bit 5-4: 11 For 10 bit PWM ??
    CCPTMRS = %11110100 ; (Page 227) CCP1 as PWM1 on Timer2 & CCP2 as PWM2 on Timer4
    APFCON0 = %00001000 ; (Page 119) CCP1/P1A/PWM1 in Port B3 , CCP2/P2A/PWM2 in Port A7
    PWM1CON = %10000000 ; (Page 229) PWM delay count 0 (0 for single output PWM)
    PWM2CON = %10000000 ; (Page 229) PWM delay count 0 (0 For single output PWM)
    PIE1 = %11110111 ; (Page 87) Enables necessary interrupts
    PIE2 = %11110001 ; (Page 88) Enables necessary interrupts
    PIE3 = %00000010 ; (Page 89) Enables necessary interrupts
    PIE4 = %00000000 ; (Page 90) Enables necessary interrupts
    PR2 = 255 ; (Pages 209 & 210) 255 for 16 MHz 10 bit 15625 Hz PWM period = 64 s
    PR4 = 255 ; (Pages 209 & 210) 255 for 16 MHz 10 bit 15625 Hz PWM period = 64 s
    ;PR2 = 255 ; (Pages 209 & 210) 255 for 32 MHz 10 bit 31250 Hz PWM period = 32 s
    ;PR4 = 255 ; (Pages 209 & 210) 255 for 32 MHz 10 bit 31250 Hz PWM period = 32 s


    Declare Serial_Baud 19200
    Declare Rsin_Pin PORTB.6 ; For Pickit3
    Declare Rsin_Mode 1 ; Inverted
    Declare Rsout_Pin PORTB.7 ; For Pickit3
    Declare Rsout_Mode 0 ; Non inverted, as inversion is made by Q1 (2N7000)
    Declare CCP1_Pin PORTB.3 ; Enhanced PWM1 output
    Declare CCP2_Pin PORTA.7 ; Enhanced PWM2 output
    Declare PortB_Pullups = 1 ; Pull up on ports B
    Declare Adin_Res = 10 ; ADC 10 bit result required (0 to 1023)
    Declare Adin_Tad = FRC ; Internal HF OSC chosen for ADC timer
    Declare Adin_Stime = 6 ; Allow 6 s sample time (Page 141 of datasheet)

    Dim i As Byte ; For sub routine Read_PWR (0 to 255)
    Dim i_1 As Byte ; For sub routine Read_SWR (0 to 255)
    Dim V_FWD_1 As Word ; i x 10 bit ADC result (0 to 1023) stored in 16 Bit (0 To 65535)
    Dim V_FWD As Float ; Mean value 32 bit floating point on i mesures in volts
    Dim Calcul_PWR_a As Float ; Intermediate calculation (3 operations max by line)
    Dim Calcul_PWR As Float ; Calculation result used by PWM for output 0 to 5 V
    ;Dim PWR_Lin As byte ; For PWM 8 bit 5 V = 100% = 255 for output 0 to 5 V
    Dim PWR_Lin As Word ; For PWM 10 Bit 5 V = 100%. To be limited to 1023 For output 0 to 5 V
    Dim V_REF_1 As Word ; i x 10 bit ADC result (0 to 1023) stored in 16 bit (0 to 65535)
    Dim V_REF As Float ; Mean value 32 bit floating point on i_1 mesures in volts
    Dim Calcul_ROS_a As Float ; Intermediate calculation (3 operations max by line)
    Dim Calcul_ROS As Float ; SWR calculation: SWR 1/1 = 0.5 V , SWR 10/1 = 5 V
    ;Dim SWR_Lin As Byte ; For PWM 8 bit 5 V = 100% = 255 for output 0 to 5 V
    Dim SWR_Lin As Word ; For PWM 10 bit 5 V = 100%. To be limited to 1023 for output 0 to 5 V

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

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #37
    Prolific Poster John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,807
    Thumbs Up
    Received: 89
    Given: 34
    Total Downloaded
    4.60 GB

    0 Not allowed!

    Default Re: PIC 18F1330 HPWM problem

    G'day Archi,
    I can't help with your question but maybe help you with getting an answer.
    It's very hard to read your code when you post as you do.
    When you post code use the advanced tab. Then when you have inserted your code highlight it with your mouse, then click on the 'code' button. From memory it's the #. This will put code html instructions around your code so that when you post your source code will keep its layout and be much easier to read.
    John
    Last edited by John Drew; 4th December 2019 at 23:02. Reason: Phone changes words

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #38
    Junior Member capitainehaddock's Avatar
    Join Date
    Oct 2019
    Posts
    26
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    87.74 MB

    0 Not allowed!

    Default Re: PIC 18F1330 HPWM problem

    Hi John
    Thanks for what to do to insert a more readable code.
    Still not working in 10 bit PWM

    i will do now
    Thanks for help
    Archi

    Code:
        Device = 16F1847
    
    
        Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_OFF, MCLRE_ON, CP_OFF, CPD_OFF, BOREN_OFF, CLKOUTEN_OFF, IESO_OFF, FCMEN_OFF
        Config2 WRT_OFF, PLLEN_ON, STVREN_OFF, LVP_ON
    
    
            Declare Xtal = 32
    
    
             ; bits               76543210
            ;OSCCON   = %11111010             ; (Page 65 of DataSheet) Set HFIntosc at 16 Mhz
            OSCCON    = %11110010             ; (Page 65 of DataSheet) Set HFIntosc at 32 Mhz
            T1CON       = %01000101             ; (Page 185) Timer 1 active as system clock (Fosc)
            T2CON       = %00000100             ; (Page 191) Timer 2 active for PWM1
            T4CON       = %00000100             ; (Page 191) Timer 4 active for PWM2
            TRISA        = %01111111             ; (Page 122) Port A7 as output, others as inputs (1= Input, 0= Output)
            ANSELA      = %00001111             ; (Page 123) Ports A0 to A3 analogic inputs (1 = Ana, 0 = Digital)
            TRISB         = %01110111             ; (Page 127) Ports B3 et B7 as outputs (1 = Input, 0 = Output)
            ANSELB      = %00000000             ; (Page 128) No Analogic affectations in Ports B, All Digital
            ADCON0     = %00001011             ; (Page 145) ADC AN2 Enabled
            ADCON1     = %11110000        ; (Page 146) AD format right justified, VREF+ = VDD & VREF- = VSS
            CCP1CON   = %00111100             ; (Page 226) Single output PWM1. bit 5-4: 11 for 10 bit PWM ??
            CCP2CON   = %00111100             ; (Page 226) Single Output PWM2. bit 5-4: 11 For 10 bit PWM ??
            CCPTMRS   = %11110100             ; (Page 227) CCP1 as PWM1 on Timer2 & CCP2 as PWM2 on Timer4
            APFCON0    = %00001000             ; (Page 119) CCP1/P1A/PWM1 in Port B3 , CCP2/P2A/PWM2 in Port A7
            PWM1CON  = %10000000             ; (Page 229) PWM delay count 0 (0 for single output PWM)
            PWM2CON  = %10000000             ; (Page 229) PWM delay count 0 (0 For single output PWM)
            PIE1           = %11110111             ; (Page 87)  Enables necessary interrupts
            PIE2           = %11110001             ; (Page 88)  Enables necessary interrupts
            PIE3           = %00000010             ; (Page 89)  Enables necessary interrupts
            PIE4           = %00000000             ; (Page 90)  Enables necessary interrupts
            ;PR2           = 255                   ; (Pages 209 & 210) 255 for 16 MHz 10 bit 15625Hz PWM period = 64 s
            ;PR4           = 255                   ; (Pages 209 & 210) 255 for 16 MHz 10 bit 15625 Hz PWM period = 64 s
            PR2            = 255                   ; (Pages 209 & 210) 255 for 32 MHz 10 bit 31250 Hz PWM period = 32 s
            PR4            = 255                   ; (Pages 209 & 210) 255 for 32 MHz 10 bit 31250 Hz PWM period = 32 s
            
                  
            Declare Serial_Baud 19200 
            Declare Rsin_Pin PORTB.6         ; For Pickit3
            Declare Rsin_Mode 1                ; Inverted
            Declare Rsout_Pin PORTB.7       ; For Pickit3
            Declare Rsout_Mode 0              ; Non inverted, as inversion is made by Q1 (2N7000)
            Declare CCP1_Pin PORTB.3       ; Enhanced PWM1 output
            Declare CCP2_Pin PORTA.7       ; Enhanced PWM2 output
            Declare PortB_Pullups = 1        ; Pull up on ports B
            Declare Adin_Res = 10           ; ADC 10 bit result required (0 to 1023)
        Declare Adin_Tad = FRC           ; Internal HF OSC chosen for ADC timer
        Declare Adin_Stime = 6           ; Allow 6 s sample time (Page 141 of datasheet)
            
        Dim i As  Byte                   ; For sub routine Read_PWR (0 to 255)
            Dim i_1 As Byte                        ; For sub routine Read_SWR (0 to 255)
            Dim V_FWD_1 As Word             ; i x 10 bit ADC result (0 to 1023) stored in 16 Bit (0 To 65535)
            Dim V_FWD As Float                 ; Mean value 32 bit floating point on i measures in volts
            Dim Calcul_PWR_a As Float       ; Intermediate calculation (3 operations max by line)
            Dim Calcul_PWR As Float          ; Calculation result used by PWM for output 0 to 5 V
            ;Dim PWR_Lin As byte              ; For PWM 8 bit  5 V = 100% = 255 for output 0 to 5 V
            Dim PWR_Lin As Word              ; For PWM 10 Bit  5 V = 100%. To be limited to 1023 For output 0 to 5 V 
            Dim V_REF_1 As Word             ; i x 10 bit ADC result (0 to 1023) stored in 16 bit (0 to 65535)
            Dim V_REF As Float                 ; Mean value 32 bit floating point on i_1 measures in volts
            Dim Calcul_ROS_a As Float       ; Intermediate calculation (3 operations max by line)
            Dim Calcul_ROS As Float          ; SWR calculation: SWR 1/1 = 0.5 V , SWR 10/1 = 5 V
            ;Dim SWR_Lin As Byte             ; For PWM 8 bit  5 V = 100% = 255 for output 0 to 5 V  
            Dim SWR_Lin As Word             ; For PWM 10 bit  5 V = 100%. To be limited to 1023 for output 0 to 5 V

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #39
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,468
    Thumbs Up
    Received: 71
    Given: 29
    Total Downloaded
    6.17 GB

    0 Not allowed!

    Default Re: PIC 18F1330 HPWM problem

    The code I posted in post #34 is for 10bit PWM, and it works as I used it a lot of times.
    Regards

    Joseph

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #40
    Junior Member capitainehaddock's Avatar
    Join Date
    Oct 2019
    Posts
    26
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    87.74 MB

    0 Not allowed!

    Default Re: PIC 18F1330 HPWM problem

    Hi Joe
    Thanks
    but my need is not for a FIXED value of duty cycle as into your post #34 or microchip examples
    but for a before calculated VARIABLE....
    and its why i donf find anywhere examples of WORKING code for my need...
    best regards
    Archi

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #41
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,468
    Thumbs Up
    Received: 71
    Given: 29
    Total Downloaded
    6.17 GB

    0 Not allowed!

    Default Re: PIC 18F1330 HPWM problem

    Ok. If you can afford that for a very short period of time you stop PWM, reload HPWM with different frequency and reload PW is the simplest way.

    Otherwise have a good read in the Wiki section here.

    Les has written an example of how to calculate frequency. It might be what you are looking for.
    Regards

    Joseph

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #42
    Junior Member capitainehaddock's Avatar
    Join Date
    Oct 2019
    Posts
    26
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    87.74 MB

    0 Not allowed!

    Default Re: PIC 18F1330 HPWM problem

    Hi Joe
    you are right
    i restudied more carefuly your past #34
    it should be applicable to my case (even if yesterday i wrote it is not applicable).
    This morning i am working around it

    I red carefuly the 10 bit PWM by Les, thanks also to him, and use it to calculate PR2,
    frequency 31250 for 10 bit with PR2 = 255 and osc 32 MHz.

    Now my code to try to have PWR_Lin variable output in 10 bit by HPWM
    is :

    Code:
            Temp_PWR = PWR_Lin                      ' Copy PWR_Lin to variable Temp_PWR
            
            RSOut " Temp_PWR " , Bin Temp_PWR, 13,10 
            CCP2CON.4 = Temp_PWR.0                  ' Place bit-0 of the duty in the LSB register (bit-4)
            RSOut " CCP2CON_1 " , Bin CCP2CON, 13,10 
            CCP2CON.5 = Temp_PWR.1                  ' Place bit-1 of the duty in the LSB register (bit-5)
            RSOut " CCP2CON_2 " , Bin CCP2CON, 13,10 
            Temp_PWR = Temp_PWR >> 2                ' Shift the duty cycle value down two places
            CCPR2L = Temp_PWR                       ' Load the MSB of the 10-bit duty value
            RSOut " CCPR2L " , Dec CCPR2L, 13,10 
            ;CCP2CON.2 = 1                           ' Already made !! Turn on PWM Module one, 
            ;CCP2CON.3 = 1                           ' Already made !! by setting bits 2 and 3 of CCP2CON 
    
    
            Temp_PWR = PWR_Lin                     ' Re-load Temp_PwR with PwR_Lin
            RSOut " Temp_PWR " , Dec Temp_PWR, 13,10 
            
            HPWM 2, PWR_Lin, 31250                         ; LINEARISED output 0 to 5 kW as 0 to 5 V after LPF
    Not working yet..... I am wrong somewhere.....

    best regards

    Archi

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #43
    Junior Member capitainehaddock's Avatar
    Join Date
    Oct 2019
    Posts
    26
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    87.74 MB

    0 Not allowed!

    Default Re: PIC 18F1330 HPWM problem

    with this code, what i get is
    a 8 bit value sent to PWM.... equal to CCP2RL ....
    as CCP2RL is only 8 bit, no way to have a 10 bit value
    still work to do....
    best regards
    Archi
    Click image for larger version

Name:	term.jpg
Views:	7
Size:	37.0 KB
ID:	3849

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #44
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,468
    Thumbs Up
    Received: 71
    Given: 29
    Total Downloaded
    6.17 GB

    0 Not allowed!

    Default Re: PIC 18F1330 HPWM problem

    Here under is a very simplified version of what I posted: -

    Code:
    PWR_Lin = 0
    Temp_PWR = PWR_Lin              ' Copy PWR_Lin to variable Temp_PWR
    HPWM 2, PWR_Lin, 31250          ' LINEARISED output 0 to 5 kW as 0 to 5 V after LP
    
    '========================================================================================
    
    Main:
    
    CCP2CON.4 = Temp_PWR.0          ' Already made !! Turn on PWM Module one, 
    CCP2CON.5 = Temp_PWR.1          ' Already made !! by setting bits 2 and 3 of CCP2CON
    
    Temp_PWR = Temp_PWR >> 2                ' Shift the duty cycle value down two places
    CCPR2L = Temp_PWR        
    
    '\ 
    ' \
    '  \   ALTER YOUR PER_Lin HERE !!
    '  /
    ' /
    '/
    
    Temp_PWR = PWR_Lin                     ' Re-load Temp_PwR with PwR_Lin
    
    GoTo Main
    
    '========================================================================================
    NOTE 1: - HPWM cannot be place in the Main section otherwise you will end up with an 8-bit value. I use HPWM just to set the frequency and kick start the PWM module. If you want to change frequency using HPWM instead of recalculating the PPR2 then do this somewhere outside the Main loop, however, note that for a brief period you will be switched to 8-bit, or otherwise pause the HPWM.

    NOTE 2: - Alter your HPWM value where I indicated.

    Add you print statements where you wish.
    Regards

    Joseph

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #45
    Junior Member capitainehaddock's Avatar
    Join Date
    Oct 2019
    Posts
    26
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    87.74 MB

    0 Not allowed!

    Default Re: PIC 18F1330 HPWM problem

    thanks for care Joseph
    but
    on your last code, i dont see how to exit value to PWM....
    i am an old beginner...
    best regards
    Archi

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. PIC with upto 8 (alt.) HPWM channels extra
      By Henk57 in forum The Lounge
      Replies: 9
      Last Post: 6th December 2015, 11:28
    2. 18F2420 -> 18F1330 UART problem
      By xldaedalus in forum Proton Plus Compiler v3
      Replies: 0
      Last Post: 28th May 2009, 23:23
    3. [SOLVED !] problem with hpwm
      By Dphil7532 in forum Proton Plus Compiler v3
      Replies: 10
      Last Post: 1st March 2007, 22:51
    4. HPWM problem
      By joesaliba in forum Proton Plus Compiler v3
      Replies: 7
      Last Post: 26th November 2006, 05:07
    5. Smalist PIC with HPWM
      By PAKirk in forum The Lounge
      Replies: 6
      Last Post: 15th August 2005, 16:31

    Members who have read this thread : 44

    Actions :  (Set Date)

    You do not have permission to view the list of names.

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts