M16C Micro timer pwm port

Sep 28, 2005 1 Replies

Hey Guys,



im trying 2 generate a pwm signal to drive a stepper motor, got hold of Mitsubishi's example code which goes like this...



#include "sfr62.h"



void main(void); void initPorts(void);



void initPorts(void) { pd0 = 0xFF; // output mode pd1 = 0xFF; // output mode pu00 = 0; // no pull up for P0_0 to P0_3 pu01 = 0; // no pull up for P0_4 to P0_7 pu02 = 0; // no pull up for P1_0 to P1_3 p1 = 0xFF; // disable LED1 and LED2 p0 = 0xFF; // turn off all segments



pd7 = 0XFF; // set port P7 to output mode pu16 = 0; // no pull up for P7_0 to P7_3 , P7_0 & P7_1 needs a pull-up pu17 = 0; // no pull up for P7_4 to P7_7 p7 = 0XFF; // initial port P7 data }



void main(void) { initPorts(); ta1mr = 0X27; //set timerA1 to 8bit PWM mode ta1 = 0X0102; //set pwm cycle to 50us tabsr = 0x02; //start the timerA1 }



Now using this code i get a signal on my pin p7.2 which is nearly 50us but i dont understand the initports function.....it changes port 0,1 and 7 to o/p mode thats ok but what is up with the "pull up" part makes no sense. For the sake of understanding i changed all the settings to port2 from port7 but that has made no difference i still get a signal at p7.2



ny help appreciated thanks Nav



Please use things words, like "to". Usenet does not charge by the byte.... oh, and I think they're going by "Renesas" now ;)

"PD" is a direction register, so I guess on the M16C a 0 means input, a

1 means output. (p = port, d = direction)

"pu" is pull up. Pull up means that the microcontroller connects the output to Vcc, through a resistor. So if you set P0_0 to '1', and the internal pullup is enabled, Vcc will come out. If the pull up is not enabled, you'll need one external to the chip on that port.

I hope I answered your question.

I would recommend that you get the Renesas datasheets and sample code from their website.

--buddy

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required