Combining PR16 & PR7 = Wireless Stepper Motor?

LED Blinking, Walking with Cytron Servo, Displaying RFID, Multi-function Mobile Robot......

Combining PR16 & PR7 = Wireless Stepper Motor?

Postby sabri » Mon Feb 13, 2012 5:11 pm

hello,

I would like to combine PR16(Sending Data Using RF Module) and PR7(Controlling Stepper Motor Using SD02B) to become one project.

My main objective is develop "wireless stepper motor".

so my question, how can I combine and modify the two modules together.

2nd question instead using push button, can I change using keyboard on my laptop or using GUI to communicate with PR16_RF_TX.

thanks for your help. truly appreciates it.
sabri
Greenhorn
 
Posts: 3
Joined: Mon Feb 13, 2012 4:49 pm

Re: Combining PR16 & PR7 = Wireless Stepper Motor?

Postby ABSF » Wed Feb 15, 2012 10:06 am

I wouldn't say it is impossible. But it's a major task to combine the two PR together. Did you do any homework before you ask this question since you're asking people how to combine and not what problems you encounter during combining?

To combine the hardware is not much of an issue, but you need to rewrite most of the software if you want it to work as you planned. The analog speed control has to be relocated from the motor board to the Tx board. The Rx board can be combined with the motor board. To control the motor wirelessly through the PC keyboard, you need to add UART to the Tx board and interface it to the PC COM port.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: Combining PR16 & PR7 = Wireless Stepper Motor?

Postby sabri » Thu Feb 16, 2012 1:02 pm

Can anyone please help me to write C programming for running stepper motor in RX board referring the flow chart given.

CODE: SELECT_ALL_CODE
//==========================================================================   
//   Project          :  Wireless Stepper Motor
//   Project description:  The receiver will receive the data(0->9) from transmitter, 
//                                  display the data on 7-segment display and rotate stepper motor.
//===========================================================================
//   include
//===========================================================================
#include <pic.h>

//===========================================================================
//    configuration
//============================================================================
__CONFIG (0x3F32);

//============================================================================
//   define
//============================================================================
#define display         PORTB
#define HEADER         0xaa
#define pulse                     RC3   //STEPPER MOTOR DRIVER
#define direction                RC4   //STEPPER MOTOR DRIVER
#define en                         RC5   //STEPPER MOTOR DRIVER

//=============================================================================
//   function prototype
//=============================================================================
unsigned char uart_rec(void);
unsigned char read_packet(void);

//============================================================================
//   main function
//============================================================================
void main(void)
{
   //assign variable
   unsigned char num,no;
                              // 7 segment display
   unsigned char _7seg[10]={0b01111111,0b00001101,0b10110111,0b10011111,   //0,1,2,3
            0b11001101,0b11011011,0b11111011,0b00001111,                  //4,5,6,7
            0b11111111,0b11011111};                                                         //8,9,
                     

   //set I/O input output
   TRISB = 0b00000000;                 //configure PORTB as output
      
   //setup USART
   BRGH = 0;               //baud rate low speed option
   SPBRG = 255;            //set boud rate to 1200bps for 20Mhz crystal
   SPEN = 1;               //enable serial port
   RX9 = 0;               //8-bit reception
   CREN = 1;               //enable reception

   num=0;
   display=_7seg[num];

   while(1)                            //infinity loop
   {
      CREN=1;                         //enable continuos receive
      if(OERR==0) no=read_packet();        //receive sata if overrun error free
      else CREN=0;                      //if overrun error, disable continuos receive
      
      if(no <= 0x09) num=no;           //only accept the value from 0 to 9

      display=_7seg[num];
   }
}

//==================================================================================
//   functions
//===================================================================================
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 received data
}



unsigned char read_packet(void)
{
   // Buffer for received byte.
   unsigned char received_byte;
   
   // Counter to indicate the current position of the received data packet.
   static unsigned char counter = 0;
   
   // Buffers for the data and checksum.
   unsigned char data;
   unsigned char checksum;
   
   
   // We loop until the checksum is correct.
   do {
      // We will ignore the sync data and assume the header byte is the start of packet.
      // Keep reading until the header byte is received.
      while (uart_rec() != HEADER);
      
      // The following byte shoulde be the data byte.
      data =    uart_rec();
      
      // Then the last byte is the checksum.
      checksum =    uart_rec();
   } while (checksum != (unsigned char)(HEADER + data));
   
   // If the checksum is correct, return the data.
   return data;
}
Attachments
Wireless Stepper Motor (RF Receiver).jpg
Wireless Stepper Motor (RF Receiver Board)
Wireless Stepper Motor (RF Transmitter).jpg
Wireless Stepper Motor (RF Transmitter Board)
sabri
Greenhorn
 
Posts: 3
Joined: Mon Feb 13, 2012 4:49 pm

Re: Combining PR16 & PR7 = Wireless Stepper Motor?

Postby sabri » Thu Feb 16, 2012 4:45 pm

Can anyone help me to check this program. I'm already test and running these program using MPLAB,
the result is ********** Build successful! **********

The problem is I'm no sure about the correct output for rotate stepper motor depend on increment number or decrement number received on the receiver board. Please help me..newbie :(

CODE: SELECT_ALL_CODE
//   Project            : Wireless Stepper Motor (RF Receiver)
//   Project description           : The receiver will receive the data(0->9) from transmitter, 
//                                              display the data on 7-segment display and rotate stepper motor.
//===========================================================================
//   include
//===========================================================================
#include <pic.h>

//===========================================================================
//    configuration
//============================================================================
__CONFIG (0x3F32);

//============================================================================
//   define
//============================================================================
#define display         PORTB
#define HEADER         0xaa
#define pulse           RC3   //STEPPER MOTOR DRIVER
#define direction       RC4   //STEPPER MOTOR DRIVER
#define en              RC5   //STEPPER MOTOR DRIVER

//=============================================================================
//   function prototype
//=============================================================================
unsigned char uart_rec(void);
unsigned char read_packet(void);
void delay (unsigned long data);  //STEPPER MOTOR
void rotate (void);               //STEPPER MOTOR
unsigned char cw=0, ccw=0, run=0; //STEPPER MOTOR

//============================================================================
//   main function
//============================================================================
void main(void)
{
   //assign variable
   unsigned char num,no;
                              // 7 segment display
   unsigned char _7seg[10]={0b01111111,0b00001101,0b10110111,0b10011111,   //0,1,2,3
                      0b11001101,0b11011011,0b11111011,0b00001111,   //4,5,6,7
                      0b11111111,0b11011111};                        //8,9,
                     

   //set I/O input output
   TRISB = 0b00000000;         //configure PORTB as output
    TRISC = 0b00000000;         //STEPPER MOTOR (set PORTC as output)
    PORTC = 0;
      
   //setup USART
   BRGH = 0;               //baud rate low speed option
   SPBRG = 255;            //set boud rate to 1200bps for 20Mhz crystal
   SPEN = 1;               //enable serial port
   RX9 = 0;               //8-bit reception
   CREN = 1;               //enable reception

   num=0;
   display=_7seg[num];

   while(1)               //infinity loop
   {
      CREN=1;                     //enable continuos receive
      if(OERR==0) no=read_packet();   //receive sata if overrun error free
      else CREN=0;               //if overrun error, disable continuos receive
      
      if(no <= 0x09) num=no;         //only accept the value from 0 to 9

      display=_7seg[num];

        if(ccw)                             //STEPPER MOTOR
        {  if(num>0)                        //STEPPER MOTOR
            {                               //STEPPER MOTOR
             rotate();                      //STEPPER MOTOR
            }                               //STEPPER MOTOR
           else                             //STEPPER MOTOR
            {                               //STEPPER MOTOR
             pulse=0;                       //STEPPER MOTOR
            }                               //STEPPER MOTOR
        }                                   //STEPPER MOTOR
        else                                //STEPPER MOTOR
        {                                   //STEPPER MOTOR
         if(num<9)                          //STEPPER MOTOR
            {                               //STEPPER MOTOR
             rotate();                      //STEPPER MOTOR
            }                               //STEPPER MOTOR
         else                               //STEPPER MOTOR
            {                               //STEPPER MOTOR
            pulse=0;                        //STEPPER MOTOR
            }                               //STEPPER MOTOR
        }                                   //STEPPER MOTOR
         
   }
}

//==================================================================================
//   functions
//===================================================================================
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 received data
}


void delay(unsigned long data)             //STEPPER MOTOR
{                                          //STEPPER MOTOR
 for( ;data>0;data-=1);                    //STEPPER MOTOR
}                                          //STEPPER MOTOR

void rotate(void)                          //STEPPER MOTOR
{                                          //STEPPER MOTOR
 unsigned char i=0;                        //STEPPER MOTOR
 ADGO=1;                                   //STEPPER MOTOR
 while(ADGO==1) continue;                  //STEPPER MOTOR
 
 if(ADRESH==0)                             //STEPPER MOTOR
 {                                         //STEPPER MOTOR
  pulse=0;                                 //STEPPER MOTOR
 }                                         //STEPPER MOTOR
 else if((255-ADRESH)<=6)                  //STEPPER MOTOR
 {                                         //STEPPER MOTOR
  i=6;                                     //STEPPER MOTOR
  pulse=1;                                 //STEPPER MOTOR
  delay(i);                                //STEPPER MOTOR
  pulse=0;                                 //STEPPER MOTOR
  delay(i);                                //STEPPER MOTOR
 }                                         //STEPPER MOTOR
 else                                      //STEPPER MOTOR
 {                                         //STEPPER MOTOR
  i=255-ADRESH;                            //STEPPER MOTOR
  pulse=1;                                 //STEPPER MOTOR
  delay(i);                                //STEPPER MOTOR
  pulse=0;                                 //STEPPER MOTOR
  delay(i);                                //STEPPER MOTOR
 }                                         //STEPPER MOTOR
}                                          //STEPPER MOTOR

unsigned char read_packet(void)
{
   // Buffer for received byte.
   unsigned char received_byte;
   
   // Counter to indicate the current position of the received data packet.
   static unsigned char counter = 0;
   
   // Buffers for the data and checksum.
   unsigned char data;
   unsigned char checksum;
   
   
   // We loop until the checksum is correct.
   do {
      // We will ignore the sync data and assume the header byte is the start of packet.
      // Keep reading until the header byte is received.
      while (uart_rec() != HEADER);
      
      // The following byte shoulde be the data byte.
      data =    uart_rec();
      
      // Then the last byte is the checksum.
      checksum =    uart_rec();
   } while (checksum != (unsigned char)(HEADER + data));
   
   // If the checksum is correct, return the data.
   return data;
}
sabri
Greenhorn
 
Posts: 3
Joined: Mon Feb 13, 2012 4:49 pm


Return to DIY Project Set

Who is online

Users browsing this forum: No registered users and 15 guests

cron