I'm using a Philips P89C668 at 16MHz in 6-clock mode. I've got a piezo (with internal driver) on P1.3 (CEX0). I'd like to switch to a speaker and output PWM to get different tones. However, I can't find any good examples on how to vary the period (frequency). I've read the Intel PCA cookbook and their one example shows how to set it at the maximum frequency, but not how to vary it or how to use other PCA sources for PWM. I don't need to vary duty cycle. Here's the PCA init:
CMOD = 0x02; // OSC/2 (6-clk mode) CCAPM0 = 0x42; // Mod0 in 8-bit PWM CCAP0H = 0x80; // set 50% duty cycle CCAP0L = 0x00; // set 50% duty cycle CH = 0x00; CL = 0x00; CR = 1; // turn it on
Sorry... I didn't realize you had asked for registers, etc. before I posted my answer. Here's an example of how to change the frequency based on your code.
CMOD = 0x04; //T0 overflow as PCA CLK CCAPM0 = 0x42; CCAP0H = 0x80; CCAP0L = 0x00; CH = 0x00; CL = 0x00; TMOD &= 0xF0; TMOD |= 0x02; //Set T0 to 8-bit timer TH0 = 0x80; //Half frequency TL0 = 0x00; TR0 = 1; //T0 Run
nothing better than a look at The PCA cookbook http://www.intel.com/design/mcs51/applnots/270609.htm Erik