Page 1 of 2

RPOR15bits.RP30R = 1; meaning

PostPosted: Fri Aug 24, 2018 11:52 am
by Manoj
I am using pic24fj256gb110.
as I was aiming to use pwm for the first time using this mcu.
I got confused here.
RPOR15bits.RP30R = 1;// used to select the out put pin .But I can not figure out what '1' defines here.
I went htrough the datasheetand noticed 'RPOR15' & 'RP30R' are there.still dont under stand what is 1 for.
please kindly help me.

Re: RPOR15bits.RP30R = 1; meaning

PostPosted: Fri Aug 24, 2018 1:16 pm
by ric
PIC24FJ256GB110 datasheet, page 138, table "TABLE 10-3: SELECTABLE OUTPUT SOURCES (MAPS FUNCTION TO OUTPUT)"
As I read that table, "1" will assign C1OUT to that pin.

Re: RPOR15bits.RP30R = 1; meaning

PostPosted: Tue Jul 09, 2019 5:35 am
by Manoj
Hello Iam using this code to get 50% PWM.
But the problem is it is not stable . its changing phase simultaneously as observed from DSO.
Code:-
TRISFbits.TRISF2 = 0; //Set RF2 as output
PORTFbits.RF2 = 0; //Initialize RF2 as low
RPOR15bits.RP30R = 18; //OC1 Output to Pin PWM
OC1CON1 = 0; // Clear registers
OC1CON2 = 0;

OC1RS = PWMpreiod-1; // PWM period
OC1R = (PWMpreiod/2)-1 ; //50% initial duty cycle
OC1CON2bits.SYNCSEL = 0b11111; //synchronized by itself
OC1CON1bits.OCTSEL = 0b111; //Peripheral clock is the source for output Compare
OC1CON1bits.OCM = 0b111;

Can any one tell me how to stabelize it?
Thank you

Re: RPOR15bits.RP30R = 1; meaning

PostPosted: Tue Jul 09, 2019 6:12 am
by ric
Show the ENTIRE program you are testing this with.
My guess is that you have not disabled the WatchDog timer, and are getting regular resets from it.

Re: RPOR15bits.RP30R = 1; meaning

PostPosted: Tue Jul 09, 2019 9:25 am
by Manoj
Sorry, The entire program is 6000+ lines long . tell me how to disable the wacthdog please.
Some example code please..
Are u asking for this part?

//

_CONFIG3(GWRP_OFF) // GWRP_OFF : General Segment Write Protect: Writes to program memory are allowed
_CONFIG2(FNOSC_PRIPLL & FCKSM_CSECMD & POSCMOD_HS & PLL_96MHZ_ON & PLLDIV_DIV2) // Primary HS OSC with PLL, Clock Switching Enabled with Failsafe Monitor, USBPLL /2
_CONFIG1(JTAGEN_OFF & FWDTEN_OFF & ICS_PGx2 ) // JTAG off, watchdog timer off

Re: RPOR15bits.RP30R = 1; meaning

PostPosted: Tue Jul 09, 2019 10:02 am
by ric
ok, it looks like the WDT is disabled.
If you can't solve it yourself, cut your program down to the minimum required to get the PWM going, and see if you still have the problem.
Do make sure you are not re-initialising the PWM over and over.

Re: RPOR15bits.RP30R = 1; meaning

PostPosted: Tue Jul 09, 2019 11:00 am
by Manoj
Exactly I am changing the pwm frequency inside a while loop. the frequebcy is increasing 2% every time

Re: RPOR15bits.RP30R = 1; meaning

PostPosted: Tue Jul 09, 2019 11:11 am
by ric
So is it stable if you DON'T change it on the fly?
If yes, then the problem is how you are updating it. You really need to do that just at the end of a cycle, so the timer count has just gone back to zero.
Or, stop the peripheral, change it, and start it again.

Re: RPOR15bits.RP30R = 1; meaning

PostPosted: Thu Jul 11, 2019 6:00 am
by Manoj
What do you exactly mean by end of the cycle?
Do you mean to update it at the end of the while loop.
By stoping the peripheral do you mean
T3CONbits.TON=0;
OC1CON1 = 0; // Clear registers
OC1CON2 = 0;
and strat again with new values

Re: RPOR15bits.RP30R = 1; meaning

PostPosted: Thu Jul 11, 2019 6:12 am
by ric
Manoj wrote:What do you exactly mean by end of the cycle?
Do you mean to update it at the end of the while loop.

No. I mean right when the timer that the PWM peripheral is using has rolled over back to zero.
That is the "start" of the PWM cycle.
If you change the PWM at any other point in time, then you add jitter.
Also, if you don't reset the timer to zero when you update the PWM parameters, you risk setting a compare value that is smaller than the current timer count, which will give you one 100% cycle.

If you are just setting the PWM to keep outputting a static value, then you can be careless about precisely WHEN you set everything.
If you're trying to rapidly vary it "on the fly", then you need to understand precisely how it works, and make sure your changes are synchronised to the waveform.