Author Topic: Set different speeds  (Read 2993 times)

0 Members and 1 Guest are viewing this topic.

Offline fang-weiTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Set different speeds
« on: June 03, 2007, 03:02:02 PM »
Hi folks!!

I have a doubt that wanted to share with all of u :D

I have programmed two timers of the microcontroller  (ATMEL 128) to obtain two pwm signals to modulate the power of a DC motor.

The thing is that if, in the main programm, if I just set the 2 pwm to a value (set_pwm1(50) , set_pwm2(100)  for example) works, and the motor runs wonderfully at that velocity. But, if I want to have different velocities, for example after one minute running with velocity "A" I want it to change to the double the velocity (ste_pwm1(100), set_pwm(200) )

it just run with the same original velocity and doesn't seem to notice that I set other parameters to the timers!!!

The timers are well programmed, because when using the whole time the same velocity it works, but I just don't know why the motor does not change the velocity when I change the settings of the timer (the OCRn value)!!! It's weird!

Could it be that it can not make abrupt changes?  :-\
By the way I am not using any interrupt...

mmm I hope I was clear enough... I didn't attach the file because it's just that: set_velocity, wait a minute, change velocity
if needed I could attach it of course.

Thank u for your time guys!


Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,702
  • Helpful? 173
    • Society of Robots
Re: Set different speeds
« Reply #1 on: June 03, 2007, 03:52:11 PM »
do you have an oscilloscope to measure the pwm?

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: Set different speeds
« Reply #2 on: June 04, 2007, 01:47:05 AM »
Is this your own code?

I am currently using code from orangutan-lib for my PWM (on an AVR based MCU), it uses one timer for the PWM signal to both motors, interrupts are used as comparators. It compiles for the ATmega168, but should be easily portable to the ATmega128. I've used the code to change PWM on the fly, and it works. Maybe you have a coding problem, a motor wiring and/or a motor driver problem (if you have one).

- Rommel
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline fang-weiTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: Set different speeds
« Reply #3 on: June 04, 2007, 04:51:48 PM »
Thanks for your answers... it works now... it was just some odd port initialization that caused problems ...

Have a good day!!



Get Your Ad Here