Hey
I am using dsPIC30F4011 with 16 MHz crystal.
I am using mikroC for dsPIC.
I have such code:
Code:
void main() {
int pwm_period1;
int i;
ADPCFG = 0xFFFF;
// initialize PWM 1, using scale 1, and Timer 2....
pwm_period1 = PWM_Init(500 , 1, 1, 2);
PWM_Start(1);
PWM_Set_Duty(0, 1); // set current duty for PWM1
while (1)
{
for(i = 0; i < pwm_period1; i++)
{
Delay_ms(1);
PWM_Set_Duty(i, 1); // set current duty for PWM1
}
}
}
I have expected it to run PWM on RE0 and RE1 pins (marked as PWM in datasheet):
But the PWM is generated on pin 23 (RD0).
Why? Am I understanding the datasheet wrong? Why the non-PWM pins are PWM?
This is one of the reason s why you need to fully understand what is actually happening in library functions.
That device has two ways of generating a PWM output: one using one of the 4 Output Compare peripherals (which have a PWM mode) and also the Motor Control PWM module that is more complex and flexible.
I do not know the library that you are using but my guess is that for a simple PWM signal it will be using one of the Output Compare modules. From the look of your code I would say that you are using Output Compare #1 which (as per Figure 13-1 of the data sheet) will output the signal on the OC1 pin which, as you have discovered, is Pin 23 which is also RD0.
Susan