CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problems with pulse steering control pic16f887

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
franklin_



Joined: 23 Mar 2011
Posts: 2
Location: Mexico

View user's profile Send private message MSN Messenger

Problems with pulse steering control pic16f887
PostPosted: Wed Mar 23, 2011 8:23 pm     Reply with quote

Hello everybody, I'm a novice in the world of pics programming, so I'm having some troubles.

lets go to the problem

I have 2 DC motors that I want to control its rotation depending on what input enters to a pin. I'm trying to do it with pulse steering control from ECCP module, but I don't understand how it works the pulse steering control. Now what I want its that when the inputs in pin B7 be 0 logical, the motors must turn to same direction simultaneusly, and when the inputs in pin B7 be a 1 logical, one motor still turns to the same direction and the other turns in opposite direction, and when appear a 0 logical, once more the two turns to the same direction; I'm doing my code helping myself from others codes but I don't really understand what I'm doing wrong; I've already the datasheet of pic but it's not clear yet for me. Please could someone help and tell me what I'm doing wrong???

The CCP2 module is simulating an input of 1's and ' 0's depending on if switch is closed or opened.

This is my code:
Code:

#include <16F887.H>
#device adc=8
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 8000000)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#define P1A PIN_C1
#define P1B PIN_D5
#define P1C PIN_D6
#define P1D PIN_D7
#byte PSTRCON = 0x9d
int8 adelante;

void set_pulse_steering(int32 steering)
{
int8 temp;

temp = make8(steering, 3);  // Get high byte only

PSTRCON = temp;   // Setup PWM steering register

// Set the TRIS to outputs for the enabled steering pins.
// Also set the selected pins to a low level.
if(temp & 1)
   output_high(P1A);
if(temp & 2)
   output_high(P1B);
if(temp & 4)
   output_high(P1C);
if(temp & 8)
   output_high(P1D);
}


void main()
{
set_tris_B(0xFF); //todos son entradas
set_tris_C(0xF9); //los pines RC1 y RC2 son salidas
set_tris_D(0xE0); //los pines RD5, RD6 y RD7 son salidas
port_b_pullups(0x00);
adelante=128;
setup_timer_2(T2_DIV_BY_1, 255, 1);
set_pwm1_duty(adelante);
setup_ccp2(adelante);
setup_ccp1(CCP_PWM_H_H);
output_low(P1B);
output_low(P1C);
output_low(P1D);
while(1)
{
   if(input(PIN_B7)==0);
      {
         while(input(PIN_B7)==0);
            {
               set_pulse_steering(CCP_PULSE_STEERING_B | CCP_PULSE_STEERING_D);
            }
      }
   if(input(PIN_B7)==1)
      {
         set_pulse_steering(CCP_PULSE_STEERING_C);
         
         while(input(PIN_B7)==1)
            {
               set_pulse_steering(CCP_PULSE_STEERING_C);
            }
      }
               
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 24, 2011 2:24 pm     Reply with quote

Pulse steering allows you to send the output pulses from one CCP channel
out on any of 4 different i/o pins, in any combination. But it's the same
signal on all the selected pins.

If you want to run a motor in forward and reverse, the normal method
is to use an H-Bridge driver. Read this tutorial on DC Motor control
from Microchip:
http://ww1.microchip.com/downloads/en/devicedoc/41233a.pdf
You can find more appnotes like that by searching for the following
search string with Google:
Quote:
site:microchip.com DC motor control -forums
franklin_



Joined: 23 Mar 2011
Posts: 2
Location: Mexico

View user's profile Send private message MSN Messenger

PostPosted: Sat Mar 26, 2011 2:40 pm     Reply with quote

ok, many thanks, I haven't read that document yet, but I achieved to make a semi control with the direction of motors, but my code it's still wrong, the idea is when the pic receives a 0 in PIN_B0, the first pwm signal comes off for P1A, and the other pwm signal must comes off for P1C, and when the pic receives a 1 in the same pin, motors should stop for a while, and then the P1A should send the same pwm signal but now P1D should be active and sending pwm signal instead P1C, but is not so, what am I doing wrong???

I post my code for suggestions
Code:

#include <16F887.H>                         
#device adc=8
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use standard_io(B)
#use standard_io(C)
#use standard_io(D)
#define P1A PIN_C1
#define P1B PIN_D5
#define P1C PIN_D6
#define P1D PIN_D7
#byte CCP1CON = 0x17
#byte PSTRCON = 0x9D
int8 adelante;

void main()
{
set_tris_B(0b10111111); //todos son entradas excepto B7
set_tris_C(0b11111001); //los pines RC1 y RC2 son salidas
set_tris_D(0b00011111); //los pines RD5, RD6 y RD7 son salidas
port_b_pullups(0b11111110);
setup_adc_ports(NO_ANALOGS);
adelante=127;
output_high(PIN_B1);
setup_timer_2(T2_DIV_BY_1, 255, 1);
set_pwm1_duty(adelante);
CCP1CON=0b00001100;
output_low(P1A);
output_low(P1B);
output_low(P1C);
output_low(P1D);


while(TRUE)
   {
      if(input_state(PIN_B0)==0)    //here receives a 0 logical and evaluates the state of pin
         {
            while(input_state(PIN_B0)==0)  //still doing the same action till receives 0 no more
               {
                  PSTRCON=0b00000101;
               }         
         PSTRCON=0b00000000;
         output_low(P1A);
         output_low(P1C);
         delay_ms(2000);
         }
   
      if(input_state(PIN_B0)==1) // the same of previous but now receiving a 1 logical
         {
            while(input_state(PIN_B0)==1)
               {
                  PSTRCON=0b00001001;
               }
         PSTRCON=0b00000000;
         output_low(P1A);
         output_low(P1D);
         }
         
   }
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group