SK40C + MD10C + DC Geared Motor + Visual Basic
Posted: Wed Dec 05, 2012 6:02 pm
Hi everyone,
I'm working on a project which one of the requirement is to control 2 motors by using a Visual Basic application. I've tested both MD10Cs and the SPG50-180K motors that I have by performing the fast test, and all 4 components works perfectly.
Then, I made a test of controlling one motor from SK40C only, whereby I connect 12V adapter to SK40C, set the jumper on MD10C to Vin, and connect the necessary connection. In the test, whenever I press SW1, the motor will turn in one direction, and when I press SW2, the motor will turn to another direction, and the test was succesful.
The third test was UART test, where by I connected SK40C alone to UC00A to my laptop. I made a dummy program whereby whenever I send a number from Hyper Terminal or my VB application (also I made a simple program for this test), the microcontroller will add 1 to the number send by my laptop and send it back to the Hyper Terminal/VB application. The test was also a success.
After all the tests mentioned, I know that there is no damage/spoil to my MD10Cs and SK40C and I also know that the UART communication works perfectly.
For now, I'm testing to control 1 motor from the Hyper Terminal. The program goes like this, whenever I send "1" from HT, the motor will turn in one direction, and when I send "2", the motor will turn in another direction. But so far, it doesn't work. I emailed Ober Choo by stating my problem and I attached the following pictures to him.**
He suggested that I connect the GND from UC00A to SK40C, and I did. So now, instead of only Tx and Rx, GND is also connected. VDD on UART is left alone. But after I did so, I found out that SK40C is now powered by UC00A. To make sure I was right, I unplugged the 12V adapter, and test the dummy program I mentioned earlier, and it works! Which is weird because I dont connect VDD and I didnt supply any power. Can anyone please explain why SK40C is powered when GND is connected?
#Edited
Btw, this is the code:
To be safe, I made a new circuit set up as shown in the picture below. Now, MD10C is powered by the power supply (14V) where the jumper is set to PWR. SK40C is powered by UC00A. The program is still the same as mentioned above on the paragprah with the double star at the end (**).To my disappointment, the circuit didn't work out like it should.
I don't know what else could I try, and that's why I'm here, to get some insight and help. Please guide me. Thank you.
I'm working on a project which one of the requirement is to control 2 motors by using a Visual Basic application. I've tested both MD10Cs and the SPG50-180K motors that I have by performing the fast test, and all 4 components works perfectly.
Then, I made a test of controlling one motor from SK40C only, whereby I connect 12V adapter to SK40C, set the jumper on MD10C to Vin, and connect the necessary connection. In the test, whenever I press SW1, the motor will turn in one direction, and when I press SW2, the motor will turn to another direction, and the test was succesful.
The third test was UART test, where by I connected SK40C alone to UC00A to my laptop. I made a dummy program whereby whenever I send a number from Hyper Terminal or my VB application (also I made a simple program for this test), the microcontroller will add 1 to the number send by my laptop and send it back to the Hyper Terminal/VB application. The test was also a success.
After all the tests mentioned, I know that there is no damage/spoil to my MD10Cs and SK40C and I also know that the UART communication works perfectly.
For now, I'm testing to control 1 motor from the Hyper Terminal. The program goes like this, whenever I send "1" from HT, the motor will turn in one direction, and when I send "2", the motor will turn in another direction. But so far, it doesn't work. I emailed Ober Choo by stating my problem and I attached the following pictures to him.**
He suggested that I connect the GND from UC00A to SK40C, and I did. So now, instead of only Tx and Rx, GND is also connected. VDD on UART is left alone. But after I did so, I found out that SK40C is now powered by UC00A. To make sure I was right, I unplugged the 12V adapter, and test the dummy program I mentioned earlier, and it works! Which is weird because I dont connect VDD and I didnt supply any power. Can anyone please explain why SK40C is powered when GND is connected?
#Edited
Btw, this is the code:
- CODE: SELECT_ALL_CODE
// include
//==============================================================================================
#include <pic.h>
// define
//==============================================================================================
// Oscillator Frequency.
//#define _XTAL_FREQ 20000000
// UART baud rate
//#define UART_BAUD 9600
// SK40C switches
#define SW1 RB0
#define SW2 RB1
// MD10C ports
#define MD10C_R_DIR RC0
#define SPEEDR CCPR2L
#define SPEEDL CCPR1L
#define MD10C_L_DIR RC3
// SK40C LED
#define LED1 RB6
#define LED2 RB7
/*******************************************************************************
* DEVICE CONFIGURATION WORDS *
*******************************************************************************/
// configuration
//==========================================================================
__CONFIG ( 0x3F32 ); //configuration for the microcontroller
// function prototype
//===========================================================================================
void delay(unsigned long data); //delay function
unsigned char uart_rec(void); //uart function (receive)
void uart_send(unsigned char data); //uart function (send)
void uart_str(const char *s); //uart function(string)
// main function
//===========================================================================================
void main(void)
{
//unsigned int received;
unsigned char send;
unsigned int a;
unsigned int b=0;
unsigned int c;
//set I/O input output
TRISB = 0b00000011; //configure PORTB I/O direction
TRISC = 0b10000000; //configure PORTC I/O direction
TRISD = 0b00000000; //configure PORTD I/O direction
//setup ADC
ADCON1 = 0b00000110; //set ADx pin digital I/O
//initialize UART
SPBRG = 129; // Configure the baud rate. Set to 9600
BRGH=1; //baud rate high speed option
TXEN=1; //enable transmission
TX9 =0; //8-bit transmission
RX9 =0; //8-bit reception
CREN=1; //enable reception
SPEN=1; //enable serial port
// initialize PWM
// Setup PWM
// Setting PWM frequency = 4.88khz
// using PIC16F877A with 20MHz Crystal
PR2 = 0xFF;
T2CKPS1 = 0;
T2CKPS0 = 1; // Timer 2 prescale = 4.
SPEEDL = 0;
SPEEDR = 0;
TMR2ON = 1; // Turn on Timer 2.
// Configure CCP1 module to operate in PWM mode.
CCP1M3 = 1;
CCP1M2 = 1;
// Configure CCP2 module to operate in PWM mode.
CCP2M3 = 1;
CCP2M2 = 1;
LED1=0;
LED2=0;
while(1)
{
a = uart_rec();
if (a==1)
{
MD10C_L_DIR = 1;
SPEEDL = 220;
}
else if (a==2)
{
MD10C_L_DIR = 0;
SPEEDL = 220;
}
}
}
// Simple delay function
//=============================================================================================
void delay(unsigned long data)
{
for( ;data>0;data-=1);
}
// UART send function
//=============================================================================================
void uart_send(unsigned char data) //function to send out a byte via uart
{
while(TXIF==0); //wait for previous data to finish send out
TXREG=data; //send new data
}
// UART receive function
//=============================================================================================
unsigned char uart_rec(void) //receive uart value
{
unsigned char rec_data;
while(RCIF==0); //wait for data
rec_data = RCREG;
return rec_data; //return the data received
}
// UART string function
//=============================================================================================
void uart_str(const char *s)
{
while(*s)uart_send(*s++);
}
To be safe, I made a new circuit set up as shown in the picture below. Now, MD10C is powered by the power supply (14V) where the jumper is set to PWR. SK40C is powered by UC00A. The program is still the same as mentioned above on the paragprah with the double star at the end (**).To my disappointment, the circuit didn't work out like it should.
I don't know what else could I try, and that's why I'm here, to get some insight and help. Please guide me. Thank you.