-
60. Re: Simple PWM
userc_38527 Feb 20, 2013 7:03 PM (in response to userc_38527)You guys mean :
void DCset( unsigned char dc ) {
PWM8_1_WritePulseWidth( dc ); /* set pulse width to generate a 50% duty cycle */
PWM8_1_Start();
} -
61. Re: Simple PWM
userc_38527 Feb 20, 2013 7:12 PM (in response to userc_38527)I can see the motor is vibrating but not moving at all...not rotating as I want....
is it because of wrong timing ?
-
62. Re: Simple PWM
ki.leung Feb 20, 2013 7:36 PM (in response to userc_38527)If you set it to 50%, your pulse width is 10ms. your servo needs to be in 1-2 ms.
Did you try your code as I suggested.
-
63. Re: Simple PWM
ki.leung Feb 20, 2013 7:44 PM (in response to userc_38527)Can you get a CRO? If you can, check the ouput pulse width of your PSOC. the period should be 20mS and pusle width should be between 1 to 2 ms.
If you cannot, then try to use a function generator. Set the freqency to 50Hz, and duty cycle should be between 5 to 10%.
-
64. Re: Simple PWM
DaKn_263916 Feb 21, 2013 5:46 AM (in response to userc_38527)My guess is the reason your servo is "hunting" is you keep restarting
PWM in a loop. If you look at the code I sent you its basically this -
main() {
startup stuff, including PWM
...
while( 1 ) {
call write pwm function with a value to set dc in it
.....
.....
}
}
When you write a new compare value, the pwm immeadiately updates itself with new
PW value, so you could glitch the output. A better way would be to modify the function
I gave you to this -
void DCset( unsigned char dc ) {
PWM8_1_Stop( );
PWM8_1_WritePulseWidth( dc ); /* set pulse width to generate a 50% duty cycle */PWM8_1_Start( );
}But even this will still produce a foreshortened pulse under some circumstances.
The way to always have these PWMs always complete current cycle first is to implement
an ISR on terminal count, set a flag in ISR, and return to main() where if you find
flag set you do the update to PWM puslewidth, and clear the flag.
Lastly in general you do not want to write any HW in a tight loop, ie. keep updating at
high speed. That can mean the HW itself never has time to adapt to the changes
being rapidly written to it repeatedly, like a servo. Thats why you use a time delay in
your while( 1 ) loop to allow servo to respond, which I see you have commented out.
Regards, Dana.
-
65. Re: Simple PWM
userc_38527 Feb 21, 2013 5:47 PM (in response to userc_38527)Hi Dana,
This is the result:
I attach the project with it, could it be the timing ?
Since it's working fine in MCS51 for rotating but it's not easy for me to transfer to cypress....
Should be easy but I don't know exactly...
Thanks for helping
-
stepper_motorV2.zip 308.8 K
-
-
66. Re: Simple PWM
userc_38527 Feb 21, 2013 5:51 PM (in response to userc_38527)The simple idea :
how can I output 0 and 1 to P0.0 in certain of time like this code :
In this line of code I don't have PWM module since it's MCS51, so it's pure 1 and 0 and timing....
void delay_us (void) //100us delay on 12Mhz
{
TH0=0;
TL0=0;
TH0 = 0xFF;
TL0 = 0x37;
TR0 = 1;
while(!TF0);
TR0 = 0;
TF0 = 0;
return;
}
void timer(int j)
{
int i;
for (i=0;i<j;i++)
{
delay_us();
}
}while(1)
{
//motor begin
count=10;
//rotate left every 45 degree begin
for(i=0;i<50;i++) // 10 equal to 5 degree
{
output=1;
timer(count);
output=0;
timer(100);
//timer(70);
}}
-
67. Re: Simple PWM
userc_38527 Feb 21, 2013 5:53 PM (in response to userc_38527)Dana, from the motor seller :
here's the spec :
Operating Speed (4.8V no load) : 0.131sec / 60 degreesit means : 131ms for 60 degree....
-
68. Re: Simple PWM
DaKn_263916 Feb 21, 2013 6:43 PM (in response to userc_38527)Do you have a datasheet for the servo, a link.
Its not a "normal" RC/Toy/Hobby servo, which is the timing we have given
you in prior posts. Based on your 131 mS comment.
Regards, Dana.
-
-
70. Re: Simple PWM
DaKn_263916 Feb 21, 2013 6:55 PM (in response to userc_38527)All I can tell you is PSOC PWM works fine with Hobby type RC servos,
with the timing we posters gave you prior.
Still curious as to what specific servo your are using.
Regards, Dana.
-
71. Re: Simple PWM
userc_38527 Feb 21, 2013 7:00 PM (in response to userc_38527)Dana,
I use : TowerPro MG996 Hi Torque digi servo
Any experience with this one ?
thanks
-
72. Re: Simple PWM
ki.leung Feb 21, 2013 7:01 PM (in response to userc_38527)1. YOU NEED TO START the PWM. it will not work if not started
2. The 3 function GenerateCenterPosition
Of course you can use the counter time delay function you mention. But you need to make sure that your period is 20ms with pulse width of 1 to 2 ms.
void
GenerateLessThan90
void
void GenerateMoreThan90
-
-
74. Re: Simple PWM
ki.leung Feb 21, 2013 7:07 PM (in response to userc_38527)The preiouse post is all corrupted.
Here is it again
1. THE PWM must be STARTED, you didn't do it in your main.c
2. The pulse width MUST between 1 to 2 ms. The value you use in the DCset MUST be between 10 and 20, same problem with the 3 generate functions.
3. UPDATE comments after changing your code. WRONG comment is worse then no comments.
4. If you use the delay timer function, Just make sure the period is 20ms with pusle width between 1 to 2 ms