DT's software PWM should work:
http://darreltaylor.com/DT_INTS-14/SPWM.html
DT's software PWM should work:
http://darreltaylor.com/DT_INTS-14/SPWM.html
"I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams
Since the 2-KHz PWM period (500-usecs) and duty cycle interval (50-usecs) is an exact multiple of the 20-KHz PWM period (50-usecs), I don't see why you couldn't use the PWM Timer 2 interrupt to update both PWM streams. That is unless interrupt code overhead becomes a significant portion of the 100 instruction cycles available between interrupts (using an 8-MHz clock).
Please forgive me for the pseudo C example (I don't have PBP).
Regards, Mike
Code:;****************************************************************** ; // setup PWM for a 50-usec period (8-MHz INTOSC, Timer 2 ; // prescale 1:1, and PR2 = 99) ; ; char duty1 = 50; // 20-KHz duty cycle, 25 or 50 ; char duty2 = 1; // 2-KHz duty cycle, 1..9 (10%..90%) ; char pwm2 = 9; // preset 2-KHz duty cycle counter ; ; void interrupt() // 50-usec interrupt intervals ; { pir1.TMR2IF = 0; // clear timer 2 interrupt flag ; ccpr1l = duty1; // update PWM1 (20-KHz) duty cycle ; pwm2++; // increment PWM2 period counter ; if(pwm2 == 10) // if end of 500-usec period ; { pwm2 = 0; gpio.1 = 1; // reset counter, turn output "on" ; } // ; if(duty2 == pwm2) // if PWM2 duty cycle match ; gpio.1 = 0; // turn PWM2 output "off" ; } // ;
Thanks for those good ideas. I'll post some code when I have it on breadboard and tested with scope.
If you only need 9 steps in your 2Khz PWM (10% each step), then Mikes idea will work just fine.
If you want 80 steps between 10-90%, I think you can use SSPWM ...
http://www.pbpgroup.com/modules/wfse...hp?articleid=6
The article lists lower maximum frequencies because it can't get 1% resolution so close to the start and end points. But if you only need 10-90%, it should be OK.
If you plan on using it, I will test it to make sure.
Since this thread was from last February, I have doubts.
DT
Thanks for the reply. I do plan on doing something with this in due course. My chip will be limited to 8mhz so
can it reach 2khz with the limited clock speed. 80 points resolution would be fine.
Great confidence I have now ... NOT!
Oh well, more things to do tomorrow I have ....
Tonight, I do this ...
Next year, you may try it.
Dutycycle of the 2Khz is 10% in the image.Code:DEFINE OSC 8 SPWMpin var GPIO.5 ' Output Pin for SSPWM INCLUDE "SSPWM.inc" ' include the SSPWM module ;----[Constants]------------------------------------------ HPWMfreq CON 20000 Freq = 2000 ' Set Frequency of SSPWM (word) ;----[Variables]------------------------------------------ HPWMduty VAR BYTE LastHPWMduty VAR BYTE SSPWMduty VAR BYTE ;----[Initialize]----------------------------------------- OSCCON = %01110000 ' 8Mhz ANSEL = %000011 ' AN0 and AN1 ANALOG DutyCycle = 10 ' Set Duty Cycle of SSPWM gosub StartSPWM ' Start SSPWM @ Freq/DutyCycle HPWM 1, 127, HPWMfreq ' Start 20Khz PWM @ 50% ;----[Main Program Loop]--------------------------------- Main: ADCIN 0, HPWMduty ADCIN 1, SSPWMduty IF HPWMDuty != LastHPWMduty THEN LastHPWMduty = HPWMDuty HPWM 1, HPWMDuty, HPWMfreq ENDIF DutyCycle = SSPWMduty*80/256+10 ' scale SSPWM dutycycle gosub SetSPWM ' Change SSPWM DutyCycle GOTO Main
Both dutycycles are adjustable from the pots, and works from 10% to 90%, (0 to 100% for the HPWM).
Don't forget to comment the wsave vars not used by the 683 in the .inc file.
Happy Holidays.
DT
Incredible I was envisaging pages of code! many thanks to Darrel
Could you post that Isis code and hex code as i have it and would like to look at the simulation.
Last edited by retepsnikrep; - 17th December 2010 at 15:57.
Bookmarks