SOME HELP WITH ROBOT´S STUFF AND MORE WITH MC68HC908JK1

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

SOME HELP WITH ROBOT´S STUFF AND MORE WITH MC68HC908JK1

1,767 次查看
mauricio2346
Contributor II
HELLO, yes i know that i use some """out-of-date"""" devices but what i can do? jejeje.  i bought a china's cheap r/c car and i modified it to be a simple robot.   the only thing (for the moment) that this little piece of plastic have to do is to follow a black line (3M black tape for example). the only problem is that mi little car is too fast to follow properly the black line.   in the program i add a kind of improvised PWM speed control in the part of motor controls on the hc908's code.
here is the piece of code:

void AdelantePWM(int pwm){
PTB_PTB3=0;
PTD_PTD2=1;
Delayms(pwm);
PTB_PTB3=0;
PTD_PTD2=0;
Delayms(pwm);
}

this code is within a library (MOTORAPI.c) and controls the main motor.
int the main code the function apears AdelantePWM(250) for example, this will turn on and off the motor during 0.25 seconds. (Delayms is a delay function).
i think that is good but i will no take a risks with that... (call me donkey if you want cause i know only the basics of hc908 architecture).   here is some stills of the "robot".  if you want to see it working please help me :smileywink:)
(sorry , i know just a little new english words.... :smileyvery-happy:)






标签 (1)
0 项奖励
回复
5 回复数

356 次查看
DustyStew
Contributor V
Hi

Your code would probably work, just not very reliably. You definitely need to use an interrupt or hardware PWM based on a timer. Your robot now only follows a black line, but you will soon want to make it do more things. If you do not use a timer to generate your pulses, then when you add new features to your robot, the PWM will probably start acting funny. The car will probably slow down whenever you tell it to do something else!

Your code would not damage the microcontroller. But you need to be sure the electronic circuit between the microcontroller and the motor protects the microcontroller. Probably the most important thing to beware of is electrical noise coming from the motor. Also make sure the current drawn from the microcontroller is not too high. I won't go into details here, because I expect that you know electronics. Your assembly work on the circuit is very good.

So try the Processor Expert idea (if this uses a timer) or answer the questions that BigMac asked in the last message, so that you can get some help setting up a timer for making your PWM.

Dusty
0 项奖励
回复

356 次查看
UcTechnoGeek
Contributor II
I like the idea of keeping it simple.
 
The JK1 timers support PWM.
 
Create your project using Processor Expert. 
Choose the PWM bean and it will create the PWM code for you.
 
You can then just use API calls to the PWM like these:
 
         PWM1_SetRatio16(word Ratio);  // sets the PWM according to a ratio 0-100%
         PWM1_SetDutyMS(word Time); // sets the PWM duty cycle by mili-seconds
 
I like to use the SetRatio command.  This way, when you set the period in the set up of the bean, you don't have to care about it anymore.  Just send a command to set the duty cycle.  Also, it's easy to make a loop in your code to increase / decrease the ratio for acceleration control.
 
Hope this helps.
 
uCTechnoGeek
0 项奖励
回复

356 次查看
mauricio2346
Contributor II
Hi!! yeah, i got it but that means i should use  PTD4 and PTD5 (unfortunately i cant modify the board of the car).  when i bought the r/c car i tought this toy wouldn't be too fast, but when i cut it.... you know, sometimes you get surprised with your proyects (especially robots). in this moment that pins controls other things of the board.  can i use this function with I/O ports???
THANKS!

0 项奖励
回复

356 次查看
bigmac
Specialist III
Hello,
 
I suspect you will need to write your own function that "bit-bangs" the PWM operation, using the required GPIO pins.  You would probably need to use the TIM channels in an "interrupt only" manner, where the output level at the GP pin will be switched within the ISR code.  This will add some degree of latency to the PWM operation, and will restrict the maximum PWM frequency that may be used.  Minimum and maximum duty cycle limits are also likely because of the processing time required by the ISRs.
 
To get a better idea of your requirements, the following additional information would need to be considered -
  1. MCU bus frequency
  2. Number of motors to be controlled
  3. Required PWM frequency
  4. Required PWM resolution
  5. Minimum first step of PWM, i.e. from motor off to the minimum run speed.
With this information, it should be possible to determine the feasibility.
 
Regards,
Mac
 
0 项奖励
回复

356 次查看
peg
Senior Contributor IV
Hi Mauricio,
 
I don't know that they are "out of date", I just shipped some products that use the JK1 the other day.
 
I like the car, it looks quite impressive, but what was the actual question?
 
0 项奖励
回复