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

Stephen Moss

@Abdullah, I recommend that you STOP what you are doing immediately.

The 33FJ12MC202 and in fact all 16-bit devices as listed here are far to complicated for you to consider using, they should only be tackled but those with a good experience of using Positron on lesser devices & using devices peripherals and interrupts. You also need to be reasonably competent at reading and understanding a devices datasheet, something which you have already stated you find difficult/are unable to do, you can't even program simpler devices unaided with any degree of competence yet.

The datasheets for 16-bit devices can exceed 100 pages, not good for someone who claims they find reading/understand them difficult, Peripheral Pin Select (PPS) is not an easy thing to understand and for the more complicated devices Peripherals are not always operational as they are in lesser device, you may have to turn them on in order to use them & Interrupts are more complicated as instead of just one or two (High & Low priority) interrupt vectors each interrupt can have its own vector/named ISR which depending on the device you may also be able to choose which priority level (High/Low) each interrupt have.

You should stick to the Standard devices in the list I linked to above until you have a lot more experience/understanding, then progress to Enhanced/high end devices, 16-bit device should be left until you have a very good understanding and a lot of experience of Positron & how PIC's and their peripherals work and the ability to read and understand datasheets.

 

Abdullah

Quote from: Stephen Moss on Today at 10:44 AM@Abdullah, I recommend that you STOP what you are doing immediately.

The 33FJ12MC202 and in fact all 16-bit devices as listed here are far to complicated for you to consider using, they should only be tackled but those with a good experience of using Positron on lesser devices & using devices peripherals and interrupts. You also need to be reasonably competent at reading and understanding a devices datasheet, something which you have already stated you find difficult/are unable to do, you can't even program simpler devices unaided with any degree of competence yet.

The datasheets for 16-bit devices can exceed 100 pages, not good for someone who claims they find reading/understand them difficult, Peripheral Pin Select (PPS) is not an easy thing to understand and for the more complicated devices Peripherals are not always operational as they are in lesser device, you may have to turn them on in order to use them & Interrupts are more complicated as instead of just one or two (High & Low priority) interrupt vectors each interrupt can have its own vector/named ISR which depending on the device you may also be able to choose which priority level (High/Low) each interrupt have.

You should stick to the Standard devices in the list I linked to above until you have a lot more experience/understanding, then progress to Enhanced/high end devices, 16-bit device should be left until you have a very good understanding and a lot of experience of Positron & how PIC's and their peripherals work and the ability to read and understand datasheets.

 
Yes sir, you are absolutely right. I agree with you 100%. The main reason for my weakness or the delay in understanding is that I don't know the English language, which makes things difficult. I am trying harder to understand so that it becomes easier for me to build programs and understand the datasheet. I am very thankful to all of you teachers who teach someone like me, an uneducated beginner, and give your valuable time. I am truly grateful, and I will try my best to understand everything properly.

It's only been about five or six months since I started working on this. I have learned mostly from videos and whatever tutorials I could find on YouTube. In Pakistan, hardly anyone works on this, and even if they do, it's on such a small level that I can't reach those people who actually do this work. That's why understanding this in my own language becomes difficult, because no one around me works on it—everyone works in C instead. This is why I am weak, and according to my education level, this language (Proton BASIC) is much easier for me compared to C++. Thank you very much. I will definitely act on your advice, InshaAllah
Abdullah

Abdullah

As for stopping it, that's difficult right now. I have to give it some time because my livelihood depends on it. Up to now, my life has basically been tied to the PIC16F676 and PIC16F684. Based on the post I'm working on, these are the only two tasks that require the most attention. This is what I'm doing
Abdullah