This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

[PWM] what ports to use?

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;
Now, does this code send output to Port 1, Pin 1? Or do we software engineers call that pin 0?

And if so, how can I send output to pin 3? Or start a second PWM signal?

What I need to do:
Send 2 different PWM signals to 2 motors. Am I doing something good here? (Motors are attached to pin0, and pin2)

Plz help this newbie... :)

ps. I did search the forums, and more, couldn't find an easy-to-use example ...

Parents Reply Children
  • 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;
    

    You can set pins on the output port by writing to this byte. Alternatively, you might take advantage of the 8051 bit-addressable instructions and declare some of the bits in the port:

    sbit Motor0 P1 ^ 0;
    sbit Motor2 P1 ^ 2;
    

    With these declarations, you can just assign "0" or "1" to Motor0 and/or Motor2 to set the appropriate pin.