Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PWM based motor control

Status
Not open for further replies.

sudarshann

Junior Member level 2
Joined
Apr 30, 2012
Messages
23
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,480
Hi
i need to control the speed of 2 dc motors with a joystick connected through pc
i have all the stuff working but i have the problem with pwm. i am using atmega16 as pwm source.
pwm values are updated as equivalents of joystick

below are my details of pwm intialization. Problem is when both OCR1AL and OCR1BL are 0% it stops
when both are 50% its in max speed . when both are in 100% it runs in some speed.
when both are in alternate one 100% and other 0% , 0% stops and 50% runs full speed . when the same is reversed bot runs at some speed. what could be the problem please help me.

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 7.813 kHz
// Mode: Fast PWM top=0x00FF
// OC1A output: Inverted
// OC1B output: Non-Inv.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0xE1;
TCCR1B=0x0D;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

Thanks in advance
 

Dear sudarshann
Hi
Can you tell me a bit more about your problem ? and if you attach the schematic that you're referring to , ( for power stage ) thus i can help you as well as possible .
Best Wishes
Goldsmith
 

Hi Goldsmith,
I am sorry i didnt make myself clear it was late night so i was in a hurry to post.

well here are the details

microcontroller used - atmega16 running at 8 mhz internal oscillator
PWM is generated by ATmega16 with the help of timer1 (16 bit timer) with the above said code initalization
motor driver circuit - IC L298N (Dual h bridge with pwm driver)
Power source is a Li poly battery 3 cell config. i also use Lead acid 12v battery also as backup.

motor driver is has 6 pins connected to the microcontroller 4 pins to drive 2 motors direction and 2 pwm pins to pwm driver.
4 pins for drive are connected to PORTA0-3 if 1010 is output then both motor rotate in clockwise. i think you must know the rest. the pwm pins are connected to the PORTD4-5 these pins the Timer1 output pins.

the atmega16 gets the pwm data from the UART which is conencted to the serialport of pc. the pc has a software which sends some packet data with 3 variables. the variables left speed, right speed, and driver direction.
left speed , right speed are values varying from 0-255 which is decoded from the joystick connected to the pc. and drive direction variable(forward, backward, left,right) is also decoded from joystick data .

the aim is drive a robot like a car driven in computer games. all the parts work fine including pwm works fine as per the config. But the problem is my pwm config is wrong as result my speed control practically varies from 0 to maximum speed and to some slower speed. i mean to i get only 3 speeds. instead of 255 speed that i am supposed to get. speed resolution is very poor. and the reason for this problem is only the timer 1 configuration ie the pwm produced is not suitable for my application i think. i also tried various combinations but none of it works properly.

please suggest me what pwm config i must use. i generated the above code with help of codevision avr evaluation. and i use that initialization code in aVR studio.

Thank you
 

Hi again
If the duty cycle of your PWM can change from zero up to 100 percent , there isn't any problem , can it change in that ambient ?
If yes , i think if you add a simple filter to your power circuit the problem will solve .
BTW : can you show me your power circuit ?
Best Wishes
Goldsmith
 

Hi Goldsmith
I am using a development board so all the stuff must be right in it i guess
development board:
~~~~~~~~~~~~
https://probots.co.in/index.php?main_page=index&cPath=61_63
motor driver board:
~~~~~~~~~~~~
https://probots.co.in/index.php?main_page=product_info&cPath=54&products_id=197

after some more carefull analysis i found this when OC1AL and OC1BL are set to 100% once is having high duty cycle and other is having a little lesser duty it seems so there seems to some speed lag. thus my robot takes a little curved path instead of a straight path.

i think using two output timer 1 could that cause some problem. can i use timer 0 and timer 1 for controlling left and right will that solve the problem.

Thanks for the reply
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top