We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, I'm kinda new to this PWM programming (And microboard program). But I've figured out the next code should start a PWM-signal.
// timer 2 initialise T2CON = 0x11; // reload value CRCL = 0x50; CRCH = 0xC9; // compare value CCL1 = 0x18; CCH1 = 0xFC; // P1.1 ??? CCEN = 0x08;
Good question ;) From my documentation: TCON, Timer Control Register CCEN, Compare/capture enable register CCL1, Compare/capture register 1, low byte CCH1, Compare/capture register 1, high byte T2CON, Timer 2 control register CRCL, Compare/reload/capture register, low byte CRCH, Compare/reload/capture register, high byte. And To try and draw it. T2 |--/-------\----| ^ ^0xFFFF | /--> CCL \--> CRC T2 = Timer, counts from 0x0000 to 0xFFFF CRC = Start, after 0xFFFF has been reached, start counting from here CCL = Compare, after this point, set pin x high (What is x? is that port 1 pin 1?)
Should be like this:
T2 |--/-------\----| ^ ^ ^0xFFFF | \--> CCL \--> CRC
I see capture, but not compare in the 535, can you put addresses on the SFRs please Erik
Adresses: T2Con, 0C8h CCL1, 0C2h CCH1, 0C3h CRCL, 0CAh CRCH, 0CBh
if you look at page 6 of http://www.semiconductors.philips.com/acrobat/datasheets/89C535.pdf you will see that these do not exist in this derivative. Happy new year Erik
Infineon (Siemens) makes an 80C535 which seems to have corresponding registers. Perhaps this is the part in question. Going back to the original post, it looks to me like the code snippet you have initializes Timer 2. But it doesn't do any output of itself. To get a pulse of a particular width out on an external pin, typically you'd do something like set the pin high, start a timer running, and let the timer interrupt handler set the pin low. It looks like this part has a fairly fancy timer 2, so you might be able to use some of those extra compare registers to store two different times, and get interrupts for both high and low transitions of your output. You can set outputs on port 1 simply by writing to the port 1 register, 90H. In Keil headers, it's usually declared:
sfr P1 = 0x90;
sbit Motor0 P1 ^ 0; sbit Motor2 P1 ^ 2;