go_away

Author Topic: Sending PWM signal requiring memory?  (Read 1378 times)

0 Members and 1 Guest are viewing this topic.

Offline BatienzaxcoreTopic starter

  • Full Member
  • ***
  • Posts: 58
  • Helpful? 0
  • Just me. Really.
Sending PWM signal requiring memory?
« on: September 08, 2012, 01:55:29 PM »
Okay... So guys, could you help me out? I'm using an FSR, a PIC16F877A, an LM293D H Bridge, and a simple DC motor. So it goes out like this. The PIC sends out a PWM signal to the motor driver, causing the motor to move.

I want to make this scenario happen:

While the PIC is sending out a PWM signal, if an abrupt and large change in the FSR's resistance (connected to the ADC port with a pull down resistor, making a force-to-voltage circuit) occurs, I want my uC to make the motor move in the reverse direction (opposite the direction of the motor before the triggering of the FSR happened), right exactly where the motor started in its initial position.

Maybe it could send out the exact same PWM signal that it sent before the FSR was triggered? Would I be needing memory stuff for this?

Could you help me out on how do I do this? I'm not really sure how am I supposed to do this in the programming part, since I was never really good at it (but my groupmates don't have anyone to depend on but me T_T). I badly need your help. Thanks for the replies.
Music is really my thing. But I am haunted by my fantasies of seeing robots rock out - A literal metal band.

Offline newInRobotics

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: Sending PWM signal requiring memory?
« Reply #1 on: September 08, 2012, 07:49:42 PM »
What You want to achieve can be done with quadrature encoder, as without it uC will not be able to tell what was initial position of the shaft of the motor.

PWM does not control position of the motor, it controls duty cycle, how many percent of total potential motor is outputting.

If You care to share what Your application is all about, You might get better suggestions.
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline BatienzaxcoreTopic starter

  • Full Member
  • ***
  • Posts: 58
  • Helpful? 0
  • Just me. Really.
Re: Sending PWM signal requiring memory?
« Reply #2 on: September 09, 2012, 12:28:12 AM »
Hmmm okay... Here's the deal. My design project involves mimicking human movement, and I chose the part for the flexion and extension of the knee. I wanted to do a exoskeletal robot manipulator that flexes and extends the user's knee for knee rehabilitation. If I press a certain button, the motor attached to the manipulator will start to move the patient's leg.

Take note: For example, the extension of the patient's leg will be the initial phase, and the second phase will be the flexion.

Then, if the patient feels pain, he has a tendency to resist the movement of the motor involuntarily (probably due to reflex or instinct). This causes a force to be applied to a force sensing resistor (located most probably at the heel of the person; the exoskeletal manipulator will be employing two of them). The FSR connected to the ADC port via a voltage divider will then send a signal to the uC, where the uC will make the motor move in the opposite direction. DO you get what I am saying?

Anyway, the real problem I am having here is about the programming stuff. In the 2 input pins of the H Bridge, I connected it to two output port pins. I was thinking of toggling the 1 and 0 coming out of it to reverse the direction of the motor, once the FSR has been triggered. The problem would be something like this; I want the uC to send the PWM signal to the motor for the same duration that it did on the initial phase of the knee manipulation, only in reverse direction, so that when the uC stops sending PWM signal, the leg of the patient after the second phase will be in its initial position before the initial phase begins.

Could you help me out on this? :( This has been putting up a toll in my body.
Music is really my thing. But I am haunted by my fantasies of seeing robots rock out - A literal metal band.

Offline Billy

  • Full Member
  • ***
  • Posts: 114
  • Helpful? 2
Re: Sending PWM signal requiring memory?
« Reply #3 on: September 09, 2012, 12:21:56 PM »
so that when the uC stops sending PWM signal, the leg of the patient after the second phase will be in its initial position before the initial phase begins.

You've already been told the correct way to do this...use encoders and monitor position.

If you want to attempt a cheaper way, try using an integrator (a variable).
as you are moving one way, count up. When you are moving the other way, count down. When you get back to zero, stop moving. 

If you need to scale the motion speed vs direction, use one multiplier moving forward and a different multiplier moving backwards.

Will this work?  Only poorly.

How about just use a mechanical switch to tell you when you're back to zero?

Offline jkerns

  • Robot Overlord
  • ****
  • Posts: 251
  • Helpful? 12
Re: Sending PWM signal requiring memory?
« Reply #4 on: September 10, 2012, 03:31:45 PM »
I want the uC to send the PWM signal to the motor for the same duration that it did on the initial phase of the knee manipulation, only in reverse direction,
So far, OK. That's pretty easy to do. If the duty cycle was constant, just use a timer.

Quote
so that when the uC stops sending PWM signal, the leg of the patient after the second phase will be in its initial position before the initial phase begins.

And this is where it falls apart. Applying the reverse torque / time profile won't move it back to the initial position.

If gravity (or any other load) were never a factor, it might come somewhat close. Sorta. But the torque (function of duty cycle) * time required to lift the leg is going to be a lot different than the torque * time required to bring it back down.

For example (not a real example, but one that should be easy to follow) the leg starts out straight down. You apply a torque to bring it up to 90 degrees from vertical. Say 10 N-m for 5 seconds. You turn the power off to the motor. It comes back to the original position all by itself. So, 10 N-m * 5 seconds does not equal 0 N-m for whatever time.

That's why people are telling you that you need a position / angle sensor if you want to bring it back to the original position. Open loop control of position by commanding torque on a system that is subject to external forces doesn't work if you are concerned about actually achieving a target position.

It's not a software /memory problem.
I get paid to play with robots - can't beat that with a stick.

http://www.ltu.edu/engineering/mechanical/bachelor-science-robotics-engineering.asp

Offline BatienzaxcoreTopic starter

  • Full Member
  • ***
  • Posts: 58
  • Helpful? 0
  • Just me. Really.
Re: Sending PWM signal requiring memory?
« Reply #5 on: September 10, 2012, 07:58:16 PM »
I want the uC to send the PWM signal to the motor for the same duration that it did on the initial phase of the knee manipulation, only in reverse direction,
So far, OK. That's pretty easy to do. If the duty cycle was constant, just use a timer.

Quote
so that when the uC stops sending PWM signal, the leg of the patient after the second phase will be in its initial position before the initial phase begins.

And this is where it falls apart. Applying the reverse torque / time profile won't move it back to the initial position.

If gravity (or any other load) were never a factor, it might come somewhat close. Sorta. But the torque (function of duty cycle) * time required to lift the leg is going to be a lot different than the torque * time required to bring it back down.


So okay, I don't think I will be able to get it back to the exact position as it was in the initial phase, according to you guys. But, can you help me out on the part where you use a timer to count the time that it sends a PWM signal for the initial phase?

I did realize that you guys are correct, though. Anyway, I don't think it would go exactly as I planned. Maybe I ought to make some magic with it then, once I see the problem with my own eyes. This part of the topic would be in a different category, so I would like to focus first on the PWM signal timer thing. Car to help me out?
« Last Edit: September 10, 2012, 08:16:43 PM by Batienzaxcore »
Music is really my thing. But I am haunted by my fantasies of seeing robots rock out - A literal metal band.

Offline newInRobotics

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: Sending PWM signal requiring memory?
« Reply #6 on: September 11, 2012, 02:52:24 AM »
This part of the topic would be in a different category, so I would like to focus first on the PWM signal timer thing.
If You want to time it only, then You have to have two timers for this task: 1st timer to run Your PWM and 2nt timer to keep track of how long You run Your PWM. In code it should look something like this:

Code: [Select]
bool raising_leg = false;
int seconds_passed = 0;

set ADC level shift interrupt;

set timer1 to run PWM;
set timer2 to call interrupts every 1 second;

raising_leg = true;

start PWM;
start timer2;

adc_level_shift_interrupt
{
      stop pwm;
      stop timer2;

      raising_leg = false;

      start timer2;
      start reverse pwm;
}

timer2_interrupt
{
      if(raising_leg)
      {
              seconds_passed++;
      }

      else
      {
             if(seconds_passed <= 0)
             {
                   stop pwm;
             }

             seconds_passed--;
      }
}

As pointed out before, gravity will do it's thing and leg will move faster along gravity force vector making Your timing useless, unless You are willing to use stepper motor, in which case timing technique is more reliable.

Also, don't forget to implement safety switches for both extremes, otherwise You can cause serious injury to someone.
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline BatienzaxcoreTopic starter

  • Full Member
  • ***
  • Posts: 58
  • Helpful? 0
  • Just me. Really.
Re: Sending PWM signal requiring memory?
« Reply #7 on: September 11, 2012, 06:43:43 AM »
Thank you Mr. NewInRobotics.

Well anyway, I will have to do some magic on the second phase of the manipulation. Since we will be focusing on a certain range of weight of leg, I will have to increase/decrease the time that is required to bring the leg of the user down. Again, thanks to you all. I will be commenting here soon if ever that I meet problems relating to the PWM signal thing. As of now, I am on the process of buying the materials needed.
Music is really my thing. But I am haunted by my fantasies of seeing robots rock out - A literal metal band.

Offline BatienzaxcoreTopic starter

  • Full Member
  • ***
  • Posts: 58
  • Helpful? 0
  • Just me. Really.
Re: Sending PWM signal requiring memory?
« Reply #8 on: September 20, 2012, 09:13:00 AM »
Oh yes. Could I ask something? Instead of doing this magic thing on the PWM signal, I decided that I should use something to measure the angle of the person's leg. Instead of using an optical encoder, I am trying to figure out if I could use a potentiometer instead. Then I would want the angle of my potentiometer displayed in an LCD display.

And finally, the flow goes like this:

Press the start button, and the uC sends a PWM signal to the motor driver. The motor lifts the leg (extension phase), and then the knob of the potentiometer is adjusted. The angle of the potentiometer would be shown in an LCD display (Starting value is 90 at upright sitting position, max value is 0 at full leg extension). Then, when the potentiometer has reached its max value, the uC will then reverse the direction of the motor and send a PWM signal until the potentiometer reaches its resistance value equal to 90 degrees starting value displayed on the LCD display.

Any thoughts or advice about this?
Music is really my thing. But I am haunted by my fantasies of seeing robots rock out - A literal metal band.

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,943
  • Helpful? 98
Re: Sending PWM signal requiring memory?
« Reply #9 on: September 20, 2012, 05:54:13 PM »
What you are really describing is a servo with some additional external logic.

Do some googling on servo control systems. Also, Microchip has a number of good App Notes on motor control and servo systems. Look them up and read.

Offline BatienzaxcoreTopic starter

  • Full Member
  • ***
  • Posts: 58
  • Helpful? 0
  • Just me. Really.
Re: Sending PWM signal requiring memory?
« Reply #10 on: September 21, 2012, 06:40:00 AM »
Could you post the link on it? I'm not really familiar with Microchip's sites. Uhm, another thing. How do I convert the angle of the potentiometer to voltage? Maybe I could use a voltage divider network, and a pull-down resistor? But I don't know how I will turn it out into a code, especially since i'm using flowcode here.
Music is really my thing. But I am haunted by my fantasies of seeing robots rock out - A literal metal band.

Offline jkerns

  • Robot Overlord
  • ****
  • Posts: 251
  • Helpful? 12
Re: Sending PWM signal requiring memory?
« Reply #11 on: September 21, 2012, 03:30:29 PM »
A potentiometer typically works fine for position feedback.
I get paid to play with robots - can't beat that with a stick.

http://www.ltu.edu/engineering/mechanical/bachelor-science-robotics-engineering.asp

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,943
  • Helpful? 98
Re: Sending PWM signal requiring memory?
« Reply #12 on: September 21, 2012, 05:48:17 PM »
Could you post the link on it? I'm not really familiar with Microchip's sites.
All the App Notes are very easy to find on Microchips site.
Just type "Application Notes" into their search box.
Or Under the "Design Support" heading the first item is "Application Notes".

If your are going to use PICs and any other electronic device then you really do need to learn how to find all the info a manufacture publishes about how to use that device.

Offline BatienzaxcoreTopic starter

  • Full Member
  • ***
  • Posts: 58
  • Helpful? 0
  • Just me. Really.
Re: Sending PWM signal requiring memory?
« Reply #13 on: September 21, 2012, 09:20:49 PM »
Mr. Jkerns, Then I would like my potentiometer to reach a certain position before I reverse the direction of the motor, presumably, it's maximum position, such that it's resistance is maximum. Then once it has returned back to its other position, the uC would stop sending out a PWM signal to stop the motor from spinning. How would I do that in my code?

Mr. waltr, I would check on that. Thank you. I will be replyin' here once I have my other issues.
Music is really my thing. But I am haunted by my fantasies of seeing robots rock out - A literal metal band.

Offline newInRobotics

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: Sending PWM signal requiring memory?
« Reply #14 on: September 22, 2012, 04:42:42 AM »
One side pin from pot goes to 5V, other side pin goes to GND, middle pin goes to ADC port of microcontroller. For ADC tutorial go to --> Newbie's Guide to the AVR ADC
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline BatienzaxcoreTopic starter

  • Full Member
  • ***
  • Posts: 58
  • Helpful? 0
  • Just me. Really.
Re: Sending PWM signal requiring memory?
« Reply #15 on: September 22, 2012, 07:57:20 AM »
Thank you Mr. newInRobotics. Although, I know how to do that already. Th problem I'm having is the code thing, and what value of a potentiometer would be preferable to use in converting it's resistance (or output voltage) to an angle output in an LCD Display.
Music is really my thing. But I am haunted by my fantasies of seeing robots rock out - A literal metal band.

Offline newInRobotics

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: Sending PWM signal requiring memory?
« Reply #16 on: September 22, 2012, 03:41:22 PM »
Th problem I'm having is the code thing, [...]
Tutorial I linked You to explains it very well.

and what value of a potentiometer would be preferable to use in converting it's resistance (or output voltage) to an angle output in an LCD Display.
Just go with 10k pot.
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline jkerns

  • Robot Overlord
  • ****
  • Posts: 251
  • Helpful? 12
Re: Sending PWM signal requiring memory?
« Reply #17 on: September 22, 2012, 04:39:31 PM »
Th problem I'm having is the code thing,

You could assume the pot is linear between 0 degrees at 0 Ohms and 10K Ohms at 350 or so degrees and then do the math to figure out the voltage as a function of angle. Or, hook up the pot and measure the voltage a a few angles.
I get paid to play with robots - can't beat that with a stick.

http://www.ltu.edu/engineering/mechanical/bachelor-science-robotics-engineering.asp

Offline BatienzaxcoreTopic starter

  • Full Member
  • ***
  • Posts: 58
  • Helpful? 0
  • Just me. Really.
Re: Sending PWM signal requiring memory?
« Reply #18 on: September 25, 2012, 05:56:33 AM »
Thank you guys. I would try that. I'm currently focusing on the program, since I'm using flowcode.
Music is really my thing. But I am haunted by my fantasies of seeing robots rock out - A literal metal band.

 


Get Your Ad Here