News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

HPWM NOT WORKING IN DSPIC 33FJ12MC202

Started by Abdullah, Dec 04, 2025, 03:52 PM

Previous topic - Next topic

Abdullah

HELLO Everyone
why are this code is not working
maybe my method is Wrong
Abdullah

Abdullah

Device 33FJ12MC202
Declare Xtal 32
Declare LCD_DTPin PORTB.0
Declare LCD_RSPin PORTB.4
Declare LCD_ENPin PORTB.5
Declare Create_Coff = On
Declare Watchdog = 0
TRISB=%00000000
Declare CCP1_Pin PORTB.10
Declare CCP2_Pin PORTB.11
Declare CCP3_Pin PORTB.8
Declare CCP4_Pin PORTB.9
Dim D1 As Byte = 127
Dim D2 As Byte = 127
Dim D3 As Byte = 127
Dim D4 As Byte = 127
Dim F1 As Word = 1000
Dim F2 As Word = 1000
Dim F3 As Word = 1000
Dim F4 As Word = 1000
Cls
Print At 1,2,"TEST HPWM 4 CH"
ABDULLAH:
HPWM 1,D1,F1
DelayMS 1
HPWM 2,D2,F2
DelayMS 1
HPWM 3,D3,F3
DelayMS 1
HPWM 4,D4,F4
DelayMS 1
GoTo ABDULLAH
End
Abdullah

Abdullah

Abdullah

Wimax

Hello,


Did you set the peripheral through PPS_Output macro or using a direct assignment ?
 
Something like this (check the device files):

PPS_Output(cOut_Pin_RPx, cOut_Fn_OC1)   ' Make RPx the pin for PWM1


Abdullah

#4
Does anyone have a demo program for dsPIC33FJ12MC202?
HPWM
Abdullah

trastikata

Is this the full program which you say is not working or you excluded some code pertaining to settings, it looks to me a lot of code is missing there?

Abdullah

Quote from: trastikata on Dec 05, 2025, 10:53 AMIs this the full program which you say is not working or you excluded some code pertaining to settings, it looks to me a lot of code is missing there?
I still have to add more things to it, but first the PWM needs to be completed. After that I will finish the rest. For now, this is the complete code.
Abdullah

trastikata

Quote from: Abdullah on Dec 05, 2025, 11:08 AM
Quote from: trastikata on Dec 05, 2025, 10:53 AMIs this the full program which you say is not working or you excluded some code pertaining to settings, it looks to me a lot of code is missing there?
I still have to add more things to it, but first the PWM needs to be completed. After that I will finish the rest. For now, this is the complete code.

So no fuses, oscillator, registers and port set-up?

Abdullah

Quote from: trastikata on Dec 05, 2025, 11:34 AM
Quote from: Abdullah on Dec 05, 2025, 11:08 AM
Quote from: trastikata on Dec 05, 2025, 10:53 AMIs this the full program which you say is not working or you excluded some code pertaining to settings, it looks to me a lot of code is missing there?
I still have to add more things to it, but first the PWM needs to be completed. After that I will finish the rest. For now, this is the complete code.

So no fuses, oscillator, registers and port set-up?
I don't know how to do it, and I also couldn't find any demo for it. Can you help me with how the oscillator is registered?"
Abdullah

trastikata

Oh boy ... There's a big difference between helping and doing everything for you. It has been suggested on several occasions to learn the basic building blocks how to setup a device before you delve in the more complex code.

Start with a simple blinking LED - make a LED blink with a period of 1s and build up from there.

Pepe

demo proteus

Abdullah

Device 33FJ12MC202
Declare Xtal 32
Declare Create_Coff = On
Declare Watchdog Off

'===========================================
' LCD CONNECTIONS
'===========================================
Declare LCD_DTPin  PORTB.0
Declare LCD_RSPin  PORTB.4
Declare LCD_ENPin  PORTB.5

'===========================================
' PIN DIRECTIONS
'===========================================
TRISB = %00000000

'===========================================
' PPS (Peripheral Pin Select) - REQUIRED
'===========================================
UnlockPPS
PPS_Output(RP10, OC1)     ' PWM1 → RB10
PPS_Output(RP11, OC2)     ' PWM2 → RB11
PPS_Output(RP8,  OC3)     ' PWM3 → RB8
PPS_Output(RP9,  OC4)     ' PWM4 → RB9
LockPPS

'===========================================
' VARIABLES
'===========================================
Dim D1 As Word = 127
Dim D2 As Word = 127
Dim D3 As Word = 127
Dim D4 As Word = 127

Dim F1 As Word = 1000
Dim F2 As Word = 1000
Dim F3 As Word = 1000
Dim F4 As Word = 1000

'===========================================
' STARTUP DISPLAY
'===========================================
Cls
Print At 1,1,"4CH PWM TEST"
DelayMS 500

'===========================================
' MAIN LOOP
'===========================================
MainLoop:
HPWM 1, D1, F1
DelayMS 1
HPWM 2, D2, F2
DelayMS 1
HPWM 3, D3, F3
DelayMS 1
HPWM 4, D4, F4
DelayMS 1
GoTo MainLoop

End
I Try this code is method of PPS_Output is wrong
 
PPS_Output(cOut_Pin_RP15, cOut_Fn_OC1)
PPS_Output(cOut_Pin_RP8, cOut_Fn_OC2)
this is working
Guide me on where you got this method from so I can read it. I checked HPWM in the manual,but I couldn't find this thing there.
Abdullah

Pepe

demo proteus

Wimax

See the remappable peripheral function section of the device datasheet.
Looking at the '[Remappable Peripheral Outputs] section of the .def file in PDS folder I see this:

"$define cOut_Fn_OC1 $12                     ' RPn tied to Output Compare 1
 $define cOut_Fn_OC2 $13                     ' RPn tied to Output Compare 2
 $define cOut_Fn_OC3 $14                     ' RPn tied to Output Compare 3
 $define cOut_Fn_OC4 $15                     ' RPn tied to Output Compare 4
(...)
 $define cOut_Pin_RP8  RPOR4bits_RP8R         ' Assign RP8 as Output Pin
 $define cOut_Pin_RP15  RPOR7bits_RP15R      ' Assign RP15 as Output Pin

"
 
so, using the macros:

PPS_Output(cOut_Pin_RP15, cOut_Fn_OC1)
PPS_Output(cOut_Pin_RP8,  cOut_Fn_OC2)

you set RP8 and RP15 as output pin for Output Compare 1 and Output Compare 2 modules.

From Positron24 User's manual:

"(...)
PPS_Output(pPin, pFunction)
The PPS_Output macro assigns a given pin as output by configuring register RPORx.
Not all devices use the same values for assigning pins to PPS, therefore, the parameters to use
within the macros can be found in each device's .def file."

trastikata

Look Abdullah, don't put the cart before the horse.

First you have to properly set your device - oscillator and fuses, before you jump to HPWM. By omitting this part of the program your program uses the default register settings. Do they (the default register settings) match your code?


Abdullah

Quote from: trastikata on Dec 05, 2025, 03:11 PMLook Abdullah, don't put the cart before the horse.

First you have to properly set your device - oscillator and fuses, before you jump to HPWM. By omitting this part of the program your program uses the default register settings. Do they (the default register settings) match your code?


Yes sir, I am studying the code carefully and trying to understand it.
I started working on dsPIC just today, so it will take me some time.
Thank you all very much — you all have helped me a lot.
Abdullah

Pepe

demo proteus without using hpwm