Hi, I need a little problem with my c-code. I'm using a PIC18F4431 to control 3 stepper motors(bi-polar). And using a Sega-pad to send 1 or 0 to the microcontroller.
I've connected only one 1 stepper motor atm, but having some difficulties with the program. I only get a response from one of the buttons on the pad.
Need help with direction etc. Does anyone know how to make i work??
Here is what I've done so far:
#include <18F4431.H>
//////////////////////////////////////////////////////////////////
//
// Demoprogram for Pulse Width Modulation (PWM).
//
// PIN_AN0 Direction forward (button)
// PIN_AN1 Direction backward (button)
// PIN_AN2 Direction right (button)
// PIN_AN3 Direction left (button)
// PIN_AN4 Direction down (button)
// PIN_AN5 Direction up (button)
// PIN_RB0,RB1,RB2,RB3,RD7,RD6 are connected to output
#fuses XT,NOBROWNOUT,NOMCLR,NOWDT,NOPROTECT,NOLVP,NOPUT
#use delay (clock=4150000)
/////////////////////////////////////////////////////////////////////
//
// Global variables.
//
// Mainprogram
void main(void) {
long duty=0;
// configurate CCP as PWM
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
// configurate timer_2
setup_timer_2(T2_DIV_BY_1, 99, 1);
// Set startup value on duty
set_PWM1_duty(duty);
set_PWM2_duty(duty);
//set_PWM3_duty(duty);
// Pin_D7 is connected to Direction input on Stepper motor driver (PBD3517)
// Pin_A0 and Pin_A1 are inputs from the Sega cotrol-pad
while( TRUE ) {
if (input(PIN_A0)==1) {
output_bit( PIN_D7, 1);
duty = 100;
set_pwm1_duty(duty);
//motor forward!
}
if (input(PIN_A0)==0){
output_bit( PIN_D7, 1);
duty = 0;
set_pwm1_duty(duty);
//motor stop!
}
//--------------------------------------
if (input(PIN_A1==1)){
output_bit( PIN_D7, 0);
duty = 100;
set_pwm1_duty(duty);
//motor backward!
}
if (input(PIN_A1)==0){
output_bit( PIN_D7, 0);
duty = 0;
set_pwm1_duty(duty);
//motor stop!
}
}//end
}
I've connected only one 1 stepper motor atm, but having some difficulties with the program. I only get a response from one of the buttons on the pad.
Need help with direction etc. Does anyone know how to make i work??
Here is what I've done so far:
#include <18F4431.H>
//////////////////////////////////////////////////////////////////
//
// Demoprogram for Pulse Width Modulation (PWM).
//
// PIN_AN0 Direction forward (button)
// PIN_AN1 Direction backward (button)
// PIN_AN2 Direction right (button)
// PIN_AN3 Direction left (button)
// PIN_AN4 Direction down (button)
// PIN_AN5 Direction up (button)
// PIN_RB0,RB1,RB2,RB3,RD7,RD6 are connected to output
#fuses XT,NOBROWNOUT,NOMCLR,NOWDT,NOPROTECT,NOLVP,NOPUT
#use delay (clock=4150000)
/////////////////////////////////////////////////////////////////////
//
// Global variables.
//
// Mainprogram
void main(void) {
long duty=0;
// configurate CCP as PWM
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
// configurate timer_2
setup_timer_2(T2_DIV_BY_1, 99, 1);
// Set startup value on duty
set_PWM1_duty(duty);
set_PWM2_duty(duty);
//set_PWM3_duty(duty);
// Pin_D7 is connected to Direction input on Stepper motor driver (PBD3517)
// Pin_A0 and Pin_A1 are inputs from the Sega cotrol-pad
while( TRUE ) {
if (input(PIN_A0)==1) {
output_bit( PIN_D7, 1);
duty = 100;
set_pwm1_duty(duty);
//motor forward!
}
if (input(PIN_A0)==0){
output_bit( PIN_D7, 1);
duty = 0;
set_pwm1_duty(duty);
//motor stop!
}
//--------------------------------------
if (input(PIN_A1==1)){
output_bit( PIN_D7, 0);
duty = 100;
set_pwm1_duty(duty);
//motor backward!
}
if (input(PIN_A1)==0){
output_bit( PIN_D7, 0);
duty = 0;
set_pwm1_duty(duty);
//motor stop!
}
}//end
}
Last edited: