PWM_MC Library function migration MikroBasic 5 to PRO 7

General discussion on mikroC PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Ulrich
Posts: 1
Joined: 14 Apr 2021 13:03

PWM_MC Library function migration MikroBasic 5 to PRO 7

#1 Post by Ulrich » 14 Apr 2021 18:22

I have an application with a self made PC -board for DC motor control, using dsPIC30F3010. I use the 2 high channels of pwm module 1 + 2 for PWM signal to motor the low channels are simply switched for direction. The channel 3 Pins are used as simple output and connected to 2 LED's. (pins in independent mode and free running)
For a long time I was working with the old compiler 5.0.
The instruction in the initialization routine

Pwm_Mc_Init(5000,$FF,$30,$3)

was working properly and without problems.

Because my old computer made trouble I changed the compiler on a new computer to PRO.
Now the function was not reconized and I had to change to

"Pwm1_Mc_Init(5000,$FF,$30,$3)"

in my code as given in the library tree.
After compilation and programming the chip the LED' did nothing, an I didnt try to connect the motor, but I was still able to read the values of my variables via Terminal and I2C bus by a function I had built in. Now the search began...
Disabling the function Pwm1_Mc_Init... the LED' worked again.

The TRISE register is set to " TRISE=$FFC0 " 'RE0- RE5 are outputs
The FB0PROR regsister is programmed to FBORPOR : $F80004 : 0x8733 so the Pins should be controlled by the tristate register.

to see what happend I added the PWMCON1, the PTCON, and the PTPER register to my "value read function"

The result was:
PWMCON1 : 119 = 01110111
PTPER : 1999; this is OK as I use a system frequency of 40MHz (10MHz crystal and 4 x PLL) for 5kHz and no prescaler. by hand calculation 5000 x 2000 = 10000000 (Tcy trigger frequency)
PTCON : 48 = 00110000; this is what I expected for no prescale and postscaler = 4 for Interrupt. (compare with datasheet)

For my Application PWMCON1 should be 3888= 0F30hex = 00001111 00110000
the bits 4 +5 ar set for the Pins of PWM channel 1 +2 High, other pins are simple IO and all pins work in independent mode.

After trying for some time
I changed the command to

Pwm1_Mc_Init(5000,$FF00,$0030,$3)

the result was PWMCON1 : 1840 = 0730hex = 00000111 00110000 , the bit no. 11 went to 0 because it is not present on the dsPIC30F3010. (only 3 channels)
now it is OK.

Nobody told me that I have to put the bit on the place as given in the PWMCON1 register.

This as a hint if someone is also working hard on this problem.

:roll: :arrow: :idea:

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: PWM_MC Library function migration MikroBasic 5 to PRO 7

#2 Post by filip » 19 Apr 2021 09:08

Hi,

Thank you for reporting this, I will present this to our developers! :)

Regards,
Filip.

Post Reply

Return to “mikroC PRO for dsPIC30/33 and PIC24 General”