joeschmoe
Newbie level 3
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!
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!