The PSMC module is not needed. For what you're trying to accomplish, one of the three Capture/Compare/PWM modules (CCP modules) can generate the variable duty cycle PWM that you need.
The first thing we need to do to set the PWM period is to write a value to register PR2. However, we must know what value to write to PR2 in order to yield a 25kHz PWM frequency, and this value is dependent on the PIC's oscillator clock frequency and the PWM frequency we are trying to achieve. The equation for this is -
(PR2 + 1) x (4 x Tosc) = PWM Period
where -
PR2 is the value written to PR2
Tosc is the period of your primary oscillator frequency (Fosc)
The easiest way to do this is to first figure out the period of a 25kHz signal. We can find this by reciprocating 25kHz -
1 / 25,000 = 40uS or microSeconds
We then find the period of our oscillator frequency. Assuming a 16MHz clock -
1 / 16,000,000 = 62.5nS or nanoSeconds
We then multiply this value by 4. This is because the instruction clock frequency is 1/4th the primary oscillator frequency -
62.5nS x 4 = 250nS
So our equation now becomes -
(PR2 + 1) x 250nS = PWM Period
Now to find the PR2 value, we simply divide the period of 25kHz by the period of the instruction clock, then subtract 1 -
(40uS / 250nS) - 1 = 159
With a 16MHz clock, a value of 159 written to PR2 will yield a PWM period of 40uS, which results in a PWM frequency of 25kHz. In assembly language, we would execute the following instructions -
Code:
movlb d'0' ;select register bank 0
movlw d'159' ;set timer 2 for PWM period of 40uS w/16MHz Fosc
movwf PR2
You would then enable Timer 2 by writing 0b00000100, or 0x04, to register T2CON. This enables timer 2 and sets it to overflow when the timer reaches the value of 159 -
Code:
movlw b'00000100' ;enable timer 2, 1:1 prescale, 1:1 postscale
movwf T2CON
Finally, write 0b00001100 to register CCP1CON to set up CCP1 in PWM mode, then write 0b00000100 to register TRISC to set up RC2 as an output (CCP1 is multiplexed onto PORTC,RC2) -
Code:
movlb d'5' ;select register bank 5
movlw b'00001100' ;CCP1 set up for PWM mode
movwf CCP1CON
movlb d'1' ;select register bank 1
bcf TRISC,RC2 ;RC2 output enable, function is CCP1 PWM output
From there you would vary the duty cycle by writing a value from 0-159 to register CCPR1L. This will yield a variable 0-5V output on pin RC2/CCP1 in steps of 31.25mV.
As far as the 200kHz 50% duty cycle square wave goes, you can generate that on any I/O pin with a timer interrupt. Set the timer to interrupt every 2.5uS and XOR the pin on each interrupt.