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

Bidirectional control of dc motor using different pwm

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



Joined: 06 Sep 2017
Posts: 82

View user's profile Send private message

Bidirectional control of dc motor using different pwm
PostPosted: Sat Oct 28, 2017 8:20 am     Reply with quote

Hello friends if i wanted to drive a motor in forward direction for some time (Let T1)using a pwm1 and then in reverse direction for another time (T2) using pwm2 . then how to do that in ccs c?? and how i determine T1 & T2.

If anyone has sample code then please share?
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Oct 28, 2017 9:08 am     Reply with quote

The code ( software) is dependent upon the motor drive electronics.
We'd have to know make/model/specs of the 'motor interface' you have or plan to use.

The actual program concept is very simple

...
set direction of controller(CW)
set PWM
enable motor( on)
delay for T1 time
disable motor(off)
set direction controller(CCW)
set PWM
enable motor(on)
...

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 28, 2017 10:36 am     Reply with quote

Setup the PWM module for an H-bridge. Then you can run the motor
forward or in reverse by using CCS functions, as shown in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=29565&start=1

Also, you should always tell us what PIC you are using.
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Oct 28, 2017 10:55 am     Reply with quote

Also the 'motor' !!

it's all about the 'little' details....

I run 5HP DC motors for the CNC mill, some people like steppers (how many phases....) then there's the RC servo motors modded to run 360*...

'motor' is too vague.
details, more is better

Jay
srikrishna



Joined: 06 Sep 2017
Posts: 82

View user's profile Send private message

PostPosted: Sun Nov 12, 2017 11:14 am     Reply with quote

temtronic wrote:
Also the 'motor' !!

it's all about the 'little' details....

I run 5HP DC motors for the CNC mill, some people like steppers (how many phases....) then there's the RC servo motors modded to run 360*...

'motor' is too vague.
details, more is better

Jay


I use normal 6v dc motor. But still can not configure how to use timer to determine the running time of a motor
srikrishna



Joined: 06 Sep 2017
Posts: 82

View user's profile Send private message

PostPosted: Sun Nov 12, 2017 11:20 am     Reply with quote

I uses the following code. But how do i use timer1 in this code to determine running time of motor

Code:
#include <18F2550.h>
#device ADC = 10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock = 20M)
#define  MOTOR_1A    PIN_B0
#define  MOTOR_1B    PIN_B1
unsigned int16 i;

void main()
{
  setup_adc(ADC_CLOCK_DIV_32);         
  setup_adc_ports(AN0);                 
  set_adc_channel(0);                   
  setup_ccp1(CCP_PWM);                 
  setup_timer_2(T2_DIV_BY_16, 250, 1); 
 
  delay_ms(100);                         
  while(1)
   {
   
   i = read_adc();
   output_high(MOTOR_1B);
   output_low(MOTOR_1A);
    set_pwm1_duty(i);                   
    delay_ms(300);
     
output_low(MOTOR_1B);
output_high(MOTOR_1A);

delay_ms(300);// Wait
   }}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Nov 12, 2017 11:31 am     Reply with quote

Use Timer1 interrupts to generate a tick (say 1 s).

Count the ticks for your forward and reverse times.

Mike
srikrishna



Joined: 06 Sep 2017
Posts: 82

View user's profile Send private message

PostPosted: Sun Nov 12, 2017 11:37 am     Reply with quote

Mike Walne wrote:
Use Timer1 interrupts to generate a tick (say 1 s).

Count the ticks for your forward and reverse times.

Mike


I just started to learning pic Can u provide any code ??
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Nov 12, 2017 12:08 pm     Reply with quote

I don't want to sound cruel, but you're supposed to work it out for yourself.
That way you'll learn from your mistakes.

I was hoping I'd given you enough guidance to proceed.

So I'll go into more detail on one way to do it, but leave the coding to you.
(Bear in mind CCS provides many examples of how to do many tasks.)

Get Timer1 to generate an interrupt.
Either adjust the interrupt time to get a 1 second interrupt or count the interrupts until you have a 1 second tick.

Create a "run_time_counter".
Use the 1 second tick to decrement this counter until it reaches zero, then stop the counter from going negative.

So to go forward for 10 seconds :-

Set run_time_counter to 10.
Set up a while loop to run whilst run_time_counter is > zero.
Run motor going forwards in the while loop, and stop when it leaves.

Do something similar for reverse.
As I've presented it you will get rounding off errors etc.
You can sort it out, but you will have something to work on.

Mike
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Nov 13, 2017 7:49 am     Reply with quote

Additionally have a look at the software RTC in the code library. It might shed some light on your task.
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