IFC series PS2 + RS08 Programming

Autonomous Robot, Manual Robot, DC Motor Driver, Stepper Motor Driver, Servo, Multi PWM chip.....

IFC series PS2 + RS08 Programming

Postby ken_alone » Thu Dec 31, 2009 3:48 pm

Can i know whether the programming below can work on IFC series card??? It can be compile but it cant work on IFC... Can anyone tell me where the problem at and how to solve it?? Thank you.....
CODE: SELECT_ALL_CODE
//   Author            : Cytron Technologies      
//   Project            : Interface Free Controller-Main Board (IFC-MB00)
//   Project description   : Sample1 for IFC-MB00
//  Date            : 21 April 2008
//
//=====================================================================================

//=====================================================================================
//   include h file for cards
//   User has to include h file for all the cards used
//=====================================================================================
#include<p18f2685.h>
#include "iic.h"
#include "iic_ps.h"
#include "iic_rs.h"

//=====================================================================================
//   configuration bit, User is advised not to change the setting here
//=====================================================================================
#pragma config OSC = HSPLL
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config BOREN = OFF
#pragma config WDT = OFF
#pragma config MCLRE = ON
#pragma config PBADEN = OFF
#pragma config DEBUG = OFF
#pragma config XINST = OFF
#pragma config LVP = OFF

//=====================================================================================
//   define input or ouput of board here
//   For example:
//            1.led1 was defined for first LED on MB00
//            2.buzzer was defined for buzzer on MB00
//   The address for input/output devide on board is fixed, hence user is
//   advised not to change the defined address for input/output
//=====================================================================================

#define   led1      LATBbits.LATB0    // led1 defined as output for first LED on MB00   
#define   led2      LATBbits.LATB1   // led2 defined as output for second LED on MB00
#define   led3      LATBbits.LATB2   // led3 defined as output for third LED on MB00
#define   led4      LATBbits.LATB3   // led4 defined as output for forth LED on MB00
#define   led5      LATBbits.LATB4   // led5 defined as output for fifth LED on MB00
#define   led6      LATBbits.LATB5   // led6 defined as output for sixth LED on MB00
#define   led7      LATBbits.LATB6   // led7 defined as output for seventh LED on MB00
#define   led8      LATBbits.LATB7   // led8 defined as output for eighth LED on MB00
#define   led         LATB         // led defined as output for ALL LED on MB00

#define   sw1         PORTAbits.RA2   // sw1 defined as input for SW1 on MB00
#define   sw2         PORTAbits.RA1   // sw2 defined as input for SW2 on MB00
#define   sw3         PORTAbits.RA0   // sw3 defined as input for SW3 on MB00
#define   buzzer      LATCbits.LATC5   // buzzer defined as output for buzzer on MB00
#define busy_led   LATCbits.LATC1   // busy_led defined as output for Busy LED on MB00
#define error_led   LATCbits.LATC2   // error_led defined as output for Error LED on MB00
#define slave_reset   LATCbits.LATC0   // slave_reset define as output to reset slave cards

//=====================================================================================
//   function prototype
//   User needs to include all the function prototype here
//   The first 4 functions prototype are fixed, user is also advised not to
//   change it.
//=====================================================================================
void ISRHigh(void);
void ISRLow(void);
void delay(unsigned long data);
void init(void);

void foward(void);
void reverse(void);
void left(void);
void right(void);
void stop(void);
//=====================================================================================
//   Main Function
//   This is the main function where program start to execute
//=====================================================================================
void main(void)
{
   //--------------------------------------------------------------------------------
   //   Program start
   //   User can start to write/modify the program here
   init();   
   while(1)
   {
      if((ps_joy,1)&&(ps_joy,4))
      foward();
      else
      stop();
   }
   {
      if((ps_joy,1)&&(ps_joy,5))
      reverse();
      else
      stop();
   }
   {   
      if((ps_joy,0)&&(ps_joy,6))
      foward();
      left();
   }
   {
      if((ps_joy,0)&&(ps_joy,7))
      foward();
      right();
   }
   //--------------------------------------------------------------------------------

   //   User is advised not to change or remove the initialization function called: "init():"
   init();                  // call initialization function of the setting in program

   while(1)
   {
      //--------------------------------------------------------------------------------
      // This program will test the 3 push buttons on MB00,
      // the push buttons are active low, hence, when any of the push button is pressed,
      // value '0' will be sent to microcontroller
      //--------------------------------------------------------------------------------
      if(sw1==0)            // Test whether SW1 is pressed
      {
         // when SW1 on board is pressed, LED 1 will ON
         // and buzzer will 'beep' for 1 time
         while(sw1==0);      // wait for SW1 being release
         led = 0x00;         // turn OFF ALL LED by sending value '0x00', if they are ON previously
         led1 =1;         // turn ON LED 1 on board by sending value '1'
         buzzer = 1;         // turn ON buzzer on board by sending value '1'
         delay(50000);      // delay for buzzer ON time
         buzzer = 0;         // turn OFF buzzer on board by sending value '0'
      }
      if(sw2==0)            // Test whether SW2 is pressed
      {
         // when SW2 on board is pressed, ALL LED will ON 
         // and buzzer will 'beep' for 2 times
         while(sw2==0);      // wait for SW1 being release
         led = 0x00;         // turn OFF ALL LED if they are ON previously
         led=0xFF;         // ALL LED ON when SW2 on board is pressed
         buzzer = 1;         // buzzer ON for first time
         delay(50000);      // delay for buzzer ON time
         buzzer = 0;         // OFF buzzer
         delay(50000);      // delay for buzzer OFF time
         buzzer = 1;         // buzzer ON for second time
         delay(50000);      // delay for buzzer ON time
         buzzer = 0;         // OFF buzzer
      }
      if(sw3==0)            // Test whether SW3 is pressed
      {
         // when SW3 is pressed, buzzer will 'beep' for 3 times
         // and ALL LED on board will blink after that
         while(sw3==0);      // wait for SW3 being release
         led = 0x00;         // turn OFF ALL LED if they are ON previously
         buzzer = 1;         // buzzer ON for first time
         delay(50000);      // delay for buzzer ON time
         buzzer = 0;         // OFF buzzer
         delay(50000);      // delay for buzzer OFF time
         buzzer = 1;         // buzzer ON for second times
         delay(50000);      // delay for buzzer ON time
         buzzer = 0;         // OFF buzzer
         delay(50000);      // delay for buzzer OFF time
         buzzer = 1;         // buzzer ON for third times
         delay(50000);      // delay for buzzer ON time
         buzzer = 0;         // OFF buzzer
         while (1)
         {
            // this is an infinity loop for blinking,
            // user need to press reset button to exit from LED blinking
            led = 0xFF;      // ON all LED
            delay (50000);   // delay for LED ON time
            led = 0x00;      // OFF all LED
            delay (50000);   // delay for LED OFF time
         }
      }
   }
}

//=====================================================================================
//   functions
//  User can write all the necessary function here
void foward()
{
      (rs_pos_sp,1,1250,255);
}
void reverse()
{
      (rs_pos_sp,1,1250,255);
}
void left()
{
      (rs_pos_sp,2,0,255);
}
void right()
{
      (rs_pos_sp,2,2500,255);
}
void stop()
{
      (rs_pos_sp,1,0,0);
}
//=====================================================================================
void delay(unsigned long data)
{
   // this is a delay function for user to use when the program need a delay
   // this function can be call by type : delay(xxxx),
   // user can replace the 'xxxx' with a value to determine how long the program
   // should delay for, the bigger the value, the longer the time of the delay
   for( ;data>0;data-=1);
}


void init(void)
{
   // this is a initialization to set the input and output of PIC18F2685
   // User is advised NOT to change the setting here
   // tris
   TRISB=0x00;            // led as output
   TRISA=0xff;            // push button as input
   TRISC=0x00;            // set port c as output
   
   // the setting for analog to digital converter, ADC for PIC18F2685
   // User is advised NOT to change the setting here
   // adc
   ADCON1=0x0F;
   
   //call the initialization function of I2C
   iic_init();      
   
   //   set the initial condition of output device on board
   //   User is advised not to change the initial condition
   led=0x00;            // turn OFF all LED on board by sending value '0x00'
   buzzer=0;            // turn OFF buzzer on board by sending value '0'
   error_led=0;         // turn OFF Error LED on board by sending value '0'
   busy_led=1;            // turn ON Busy LED on board by sending value '1'
   slave_reset=1;         // reset slave cards
   delay(10000);         
   slave_reset=0;         
   delay(50000);         
   busy_led=0;            // turn OFF Busy LED on board by sending value '0'
}


//=====================================================================================
//   Interrupt vector
//=====================================================================================
#pragma   code InterruptVectorHigh = 0x08
void InterruptVectorHigh(void)
{
    _asm
      goto ISRHigh      // jump to interrupt routine
   _endasm
}
#pragma code
#pragma   code InterruptVectorLow = 0x18
void InterruptVectorLow(void)
{
    _asm
      goto ISRLow         // jump to interrupt routine
   _endasm
}
#pragma code

//=====================================================================================
//   Interupt Service Routine
//   this a function reserved for interrupt service routine
//   User may need it in advance development of the program
//=====================================================================================
#pragma interrupt ISRHigh
void ISRHigh(void)
{

}

#pragma interrupt ISRLow
void ISRLow(void)
{

}
ken_alone
Apprentice
 
Posts: 34
Joined: Thu Dec 31, 2009 3:40 pm

Re: IFC series PS2 + RS08 Programming

Postby ober » Thu Dec 31, 2009 4:19 pm

hi, can you elaborate more? Which part does not work? We cannot review all the source codes. The servo part does not work or the PS2 part cannot work?

Is the address of PS card and Servo being configured same as the code? Is the error LED light on when the program run?
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1441
Joined: Wed Apr 15, 2009 1:03 pm

Re: IFC series PS2 + RS08 Programming

Postby ken_alone » Thu Dec 31, 2009 7:11 pm

I had been programmed the code with
init();
while(1)
{
if((ps_joy,1)&&(ps_joy,4))
foward();
else
stop();
}
and
void foward()
{
(rs_pos_sp,1,1250,255);
}
does this kind of programming right??
i'm not sure my programming problem or the the output having problem...
The ps card indicate with button pressed but i dunno whether the program works...
Because when i moved the analog, the rs channel 1 does not response
ken_alone
Apprentice
 
Posts: 34
Joined: Thu Dec 31, 2009 3:40 pm

Re: IFC series PS2 + RS08 Programming

Postby sich » Thu Dec 31, 2009 8:32 pm

Can see that the codes after the lines below is unused because of the while loop:

CODE: SELECT_ALL_CODE
while(1)
{
      if((ps_joy,1)&&(ps_joy,4))
      foward();
      else
      stop();
}


So basically ur main program only execute the few lines above?

Then the forward function also seems weird...are u sure the routine in the forward function is correct? Can u successfully build ur program in MPLAB?
~> How to ask QUESTIONS the SMART way in FORUM? <~
User avatar
sich
Moderator
 
Posts: 603
Joined: Tue Apr 21, 2009 2:15 pm

Re: IFC series PS2 + RS08 Programming

Postby A380 » Thu Dec 31, 2009 8:34 pm

ken_alone WROTE:I had been programmed the code with
init();
while(1)
{
if((ps_joy,1)&&(ps_joy,4))
foward();
else
stop();
}
and
void foward()
{
(rs_pos_sp,1,1250,255);
}
does this kind of programming right??


(ps_joy,1);, (rs_pos_sp,1,1250,255);?
what is this?
i think ur function called incorrectly.
i dun think this program can be built succeed.
User avatar
A380
Discoverer
 
Posts: 119
Joined: Tue May 19, 2009 2:44 pm
Location: Malaysia

Re: IFC series PS2 + RS08 Programming

Postby ken_alone » Wed Jan 06, 2010 8:21 pm

Sorry bout the last programming.... I made it mistaken.... I have another question, how do we set rs 08 card as disable for all the channel before any ps button was pressed?? I built my program but the servos started to rotate when i connect the power supply into it.... So how should i program to enable rs-08 be in low condition for all channel??
N one more, how can i program the rotation for servos? This is because i would like to make some fix degrees rotation, was it related with PWM?? Can explain it to me??? Thx for your notification....
ken_alone
Apprentice
 
Posts: 34
Joined: Thu Dec 31, 2009 3:40 pm

Re: IFC series PS2 + RS08 Programming

Postby hyng » Fri Jan 08, 2010 10:07 am

It nature for a normal RC servo to rotate a bit a while in free when u supply power to it. So please on the power first before enter into your main program.
The RS08 has function to disable the rc servo - rs_en(address, channel, enable/disable). For all channel, the second byte is zero.
To control/rotate a rc servo, what you do is give the function rs_pos_sp(address, channel, position, speed). Position value is from 0-5000 steps.
Please read the RS08 card library function manual first in the website. All function have been describe there. I'm sure it is pretty easy to understand the manual.
User avatar
hyng
Moderator
 
Posts: 292
Joined: Thu Apr 16, 2009 11:35 am

Re: IFC series PS2 + RS08 Programming

Postby ken_alone » Wed Jan 20, 2010 9:42 am

i would like to ask.... I had written my programming and burned my hex code to IFC-MB. But when i connect supply only to main board, the RS-08 card appear to be nothing but l.e.d blinking. But when i connect a 12v to my rs-08, my motor operates directly without taking any response from my controller. How can i check whether the signal reaches rs-08 or something wrong with my rs-08? In another way, my connection for the IFC cards starting from bottom were power card-main board-ps01-rs-08, were this assemble correct?
thx for your attention and reply....
ken_alone
Apprentice
 
Posts: 34
Joined: Thu Dec 31, 2009 3:40 pm

Re: IFC series PS2 + RS08 Programming

Postby hyng » Thu Jan 21, 2010 1:17 pm

I'm not so clear about your problem.
1. Which LED is blinking? Busy led? Always blinking? It's normal if the busy LED is light ON for a while (ONLY blink once) after you on the main switch on PC00.
2. What you mean by operates directly? Can you elaborate more? So it operates according to your code? Or the servo motors are rotating at their own will? If it is operates to your code, can you please verify your code? Maybe you can have a start button in your program so that the motor will only start to operate when you press the button.
3. The assemble part should not have problem.

Anyway, you can fill in the support form under the support tab at our website www.cytron.com.my if you think the IFC card got problem.
User avatar
hyng
Moderator
 
Posts: 292
Joined: Thu Apr 16, 2009 11:35 am

Re: IFC series PS2 + RS08 Programming

Postby hyng » Thu Jan 21, 2010 1:19 pm

Another suggestion: have you tested with the SAMPLE code? Is it runs according to the code? (I assume you understand the C code ;) )
User avatar
hyng
Moderator
 
Posts: 292
Joined: Thu Apr 16, 2009 11:35 am

Next

Return to Robot Controller

Who is online

Users browsing this forum: No registered users and 1 guest

cron