how to use pwm port as I/O port ?

Discussion in 'Embedded Systems and Microcontrollers' started by turo2003, Oct 19, 2011.

  1. turo2003

    Thread Starter New Member

    Oct 14, 2011
    12
    0
    hi,
    I'm using dspi30f4011, it has 3 pwm outputs (6 pin in total),
    this dspic has the following pins :

    pin 38 : pwm1L/re0
    pin 37 : pwm1H/re1
    pin 36 : pwm2L/re2
    pin 35 : pwm2H/re3
    pin 34 : pwm3L/re4
    pin 33 : pwm3H/re5

    I want to use pwm2h as pwm signal and re2,re4,re5 as I/O ports

    I have written the following:


    #include "p30f4011.h"
    int main(void)
    {
    PTCONbits.PTEN = 0; // Timer Enable bit:
    PWMCON1bits.PMOD2 = 1; // PWM I/O pin pair is in the independent output mode
    PWMCON1bits.PMOD3 = 1; // PWM I/O pin pair is in the independent output mode
    PWMCON1bits.PEN2H = 1; // PEN2H (pin 35) is enabled for PWM output
    PWMCON1bits.PEN2L = 0; // PWM2L (pin 36) disabled. I/O pin becomes general purpose I/O
    PWMCON1bits.PEN3L = 0; // PWM3L (pin 34) disabled. I/O pin becomes general purpose I/O
    PWMCON1bits.PEN3H = 0; // PWM3H (pin 33) disabled. I/O pin becomes general purpose I/O
    TRISBbits.TRISB0 = 0; //led
    TRISEbits.TRISE2 = 0; //INa to H-bridge
    TRISEbits.TRISE5 = 0; //INb to H-bridge
    TRISEbits.TRISE4 = 1; //CS from H-bridge

    while(1)
    {
    PORTBbits.RB0 = 1; // led
    PORTEbits.RE2 = 1; // INa
    PORTEbits.RE5 = 1; // INb
    }
    }



    I dont have a problem with the pwm (this is not the whole code), I have a problem the I/O port pins.
    when I connect the scope to pwm2L it shows me the same pwm signal as in pwm2H, as if they are complementary but I chose them to be independent!
    the re4 abd re5 port show about 1v all thime..

    what the problem ?
     
  2. turo2003

    Thread Starter New Member

    Oct 14, 2011
    12
    0
    I'm trying to connect port e pins to H-bridge, do I have to connect pull-down resistors to the outputs ?
     
Loading...