SK40C + MD10C + DC Geared Motor + Visual Basic

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

SK40C + MD10C + DC Geared Motor + Visual Basic

Postby Abdullah » 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.**

P1040244.jpg
LHS is MD10C and RHS is SK40C

P1040245.jpg
Circuits connection

P1040247.jpg
Circuit Connection - Close up


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.

P1040248.jpg
Latest circuit set up


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.
Abdullah
Newbie
 
Posts: 8
Joined: Wed Dec 05, 2012 1:23 pm

Re: SK40C + MD10C + DC Geared Motor + Visual Basic

Postby Abdullah » Wed Dec 05, 2012 8:58 pm

Out of curiosity, I changed the the while loop as following, while other parts of the code remain the same:

CODE: SELECT_ALL_CODE
while(1)
   {   

      a = uart_rec();
   

      if (a==1)
      {   
         LED1=1;
         LED2=0;
      }
      else if (a==2)
      {
         LED2=1;
         LED1=0;
      }
      
   }


This is for me to see whether the communication does really happen. For the hardware, I remove MD10C board and let alone SK40C and UC00A (with VDD and GND connected to SK40C). When I ran the program, I failed to turn on the LEDs. I'm guessing that the problem lies on the 'if loop'. Any ideas?
Abdullah
Newbie
 
Posts: 8
Joined: Wed Dec 05, 2012 1:23 pm

Re: SK40C + MD10C + DC Geared Motor + Visual Basic

Postby robosang » Wed Dec 05, 2012 9:51 pm

Good explanation and good photos :mrgreen: Like it!

A weird thing about the SK40C being powered by UC00A even the VDD is not connected. Is the motor driver being power at that time? I do not have MD10C with me so cannot really help you. Just can suggest some trial and error method.

Why don you power the SK40C with adapter too? You can always add in LED to indicate where is the program now.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: SK40C + MD10C + DC Geared Motor + Visual Basic

Postby robosang » Wed Dec 05, 2012 10:03 pm

If you are using HyperTerminal..... it should be ASCII instead of decimal value
CODE: SELECT_ALL_CODE
    while(1)
       {   

          a = uart_rec();
       

          if (a=='1')
          {   
             LED1=1;
             LED2=0;
          }
          else if (a=='2')
          {
             LED2=1;
             LED1=0;
          }
         
       }
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: SK40C + MD10C + DC Geared Motor + Visual Basic

Postby Abdullah » Wed Dec 05, 2012 10:48 pm

robosang WROTE:Good explanation and good photos :mrgreen: Like it!


I've been around this forum for quite some time as an observer. Hence I know some of things people want from the poster :D

robosang WROTE: A weird thing about the SK40C being powered by UC00A even the VDD is not connected. Is the motor driver being power at that time?


During that time, I didn't turn on the 12V power adapter and I connected UC00A (without VDD connected) to my laptop and SK40C, and the power led on SK40C dimly lighted up. Also, MD10C wasn't powered up.

robosang WROTE: Why don you power the SK40C with adapter too? You can always add in LED to indicate where is the program now.


By saying "power the SK40C with adapter too", I'm assuming that you were suggesting me to power up SK40C using the 12V adapter eventhough the SK40C is powered by UC00A (without VDD connected). If my assumption is correct, then my reply to this is, I actually tried this method already, and no surprise, it still not working.

robosang WROTE:If you are using HyperTerminal..... it should be ASCII instead of decimal value


This could be the problem. I'll try this tomorrow when I get my hands on the hardware.

Thank you Robosang.
Abdullah
Newbie
 
Posts: 8
Joined: Wed Dec 05, 2012 1:23 pm

Re: SK40C + MD10C + DC Geared Motor + Visual Basic

Postby Abdullah » Wed Dec 05, 2012 11:09 pm

Abdullah WROTE:
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.


Referring to above quote from my first post, I have a question. Is it safe for the motor? This is because the motor is rated to be 12V, but by doing as mentioned above, the motor is powered by 14V. :?
Abdullah
Newbie
 
Posts: 8
Joined: Wed Dec 05, 2012 1:23 pm

Re: SK40C + MD10C + DC Geared Motor + Visual Basic

Postby robosang » Thu Dec 06, 2012 9:54 am

You worry too much! I have been using motor rated 12V at 24V :) Of course it will get hotter, and the brush will ware off faster, but it will not be 1 or 2 minutes to kill the motor, it take me few days to weeks to kill it. Brush motor will die eventually when the brush run out :)
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: SK40C + MD10C + DC Geared Motor + Visual Basic

Postby Abdullah » Thu Dec 06, 2012 11:45 am

Hi everyone, good morning :D

Just now I've changed the code as per suggested by robosang, and during the test, I could turn on/turn off LED1 and LED2 by sending the number "1" and "2" respectively. For the test, SK40C was powered by UC00A, and I disconnect MD10C from Sk40C. However, after few times changing the number, the circuit become less responsive. What I mean by this, I had to press either "1" or "2" few times before SK40C turn on/turn off the respective LEDs. Do note that the Tx LED on UC00A blinked everytime I pressed a number, which means that the number was sent to SK40C. I realised then, that the PWR LED on SK40C was dim, but I didn't think it was the problem.

Without actually solved the problem, I proceeded to change the code as written below.
CODE: SELECT_ALL_CODE
while(1)
   {   

      a = uart_rec();


      if (a =='1')
      {          
         MD10C_L_DIR = 1;
         SPEEDL = 220;
         LED1 =1;
         LED2 = 0;
      
      }
      else if (a=='2')
      {   
         MD10C_L_DIR = 0;
         SPEEDL = 220;
         LED2=1;
         LED1=0;
      }
      
   }


My fear that there will be a problem turning the motor became true. The motor turned, but it wasn't smooth turning. I noticed that the A and B LEDs on MD10C were both lighted up, but one is brighter than the other.

Suspecting that the problem is because of SK40C, I hold the VDD cable from UC00A, and as expected, the PWR LED turned on brightly. Hence, I redo the motor test while holding VDD cable, and then the motor turns smoothly. :D So, the problem was actually VDD cable loosely connected from UC00A to SK40C. So now, I can turn the motor in either direction by sending either number "1" or "2" from HyperTerminal :D . Below is the hardware setup.

P1040250.jpg
Latest hardware setup


robosang WROTE:You worry too much! I have been using motor rated 12V at 24V :) Of course it will get hotter, and the brush will ware off faster, but it will not be 1 or 2 minutes to kill the motor, it take me few days to weeks to kill it. Brush motor will die eventually when the brush run out :)


I guess I am. :| Anyhow, thank you robosang. :)

#EDITED
I think I should also mention that I put the jumper on MD10C to PWR, and supply a 12V to the board, and it is still works. Would this badly affect anything?
Abdullah
Newbie
 
Posts: 8
Joined: Wed Dec 05, 2012 1:23 pm

Re: SK40C + MD10C + DC Geared Motor + Visual Basic

Postby robosang » Thu Dec 06, 2012 5:37 pm

Good to hear that.

Not sure on the MD10C jumper, might need to check the User's Manual/datasheet for details. :mrgreen:
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: SK40C + MD10C + DC Geared Motor + Visual Basic

Postby Abdullah » Thu Dec 06, 2012 7:11 pm

Personally, I don't think it affects MD10C in a bad way. Since I notice PWR LED on MD10C will light up quite bright when the voltage supplied is 6V, so I guess that the board will work even with 12V power supplied.

And I did a test by supplying 12V and press the A and B button just to see the motor responds, and it responded nicely. Or maybe I should say, the respond is the same as when I supplied 14V.
Abdullah
Newbie
 
Posts: 8
Joined: Wed Dec 05, 2012 1:23 pm

Next

Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 6 guests