Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PWM Motor Control via SerialPort to PIC16F877A from VB 2010

Status
Not open for further replies.

joeschmoe

Newbie level 3
Joined
Apr 14, 2011
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,315
Hi guys i was just wondering because i have to control a dc motor using pwm with a PIC16F877A. I don't have any problems controlling a dc motor with just the microcontroller. My main problem is that i made a GUI on Visual Basic 2010 and i want to control the motor by sending a byte through the serialport to the uart pin of the pic. Here's my code for the PIC16f877a:

void InitSettings(){
PORTC=0;
TRISC=0;

UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
UART1_Write(10);
UART1_Write(13);

Pwm1_Init(5000);
Pwm1_start();
}

void main(){
int uart_rd;

InitSettings();
while (1) {
if (UART1_Data_Ready()) { // If data is received,
uart_rd = (UART1_Read()); // read the received data,
Uart1_write(uart_rd);
Pwm1_Set_Duty(uart_rd); //75% of 255 (255*0.75=192)
}
}
}

I don't get what I'm doing wrong. My program in VB sends a byte through the serial port for example 255 which gets converted to ASCII because of the MAX232 circuit so shouldn't uart_rd be = to 255 and set the duty cycle as 255?

Thanks in advance for your help!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top