Shahariar
Published © GPL3+

PSoC 4 : How to Control a Servo

This is a tutorial about controlling a Servo with PSoC by generating PWM, adjusting Frequency and Duty Cycle!

IntermediateProtip1 hour9,622
PSoC 4 : How to Control a Servo

Things used in this project

Hardware components

PSoC 4 Prototyping Kit
Cypress PSoC 4 Prototyping Kit
×1
Servos (Tower Pro MG996R)
Micro Servo SG90 Tower Pro
×1

Story

Read more

Schematics

Servo connections to PSoC

Code

Main C

C/C++
Controlling Duty Cycle on the Fly
/* ========================================
 *
 * Copyright YOUR COMPANY, THE YEAR
 * All Rights Reserved
 * UNPUBLISHED, LICENSED SOFTWARE.
 *
 * CONFIDENTIAL AND PROPRIETARY INFORMATION
 * WHICH IS THE PROPERTY OF your company.
 *
 * ========================================
*/
#include <project.h>
//long freq=50;
int x=4520;
int main()
{
    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    PWM0_Start();
  
     CyGlobalIntEnable;  /* Uncomment this line to enable global interrupts. */
    for(;;)
    {
    
    while(1)
    {
     
    
  
    while(1)
    {
        
       PWM0_WriteCompare(x); 
        x+=24;
        CyDelay(1500);
        if (x>=4540){x=4320;}
    }

    
    }
    
    }
      
   
}

PSoC Codes and Design Files

C/C++
PSoC 4 : 4245 AXI/ ARM M0/ Cy8C049 Kit !
No preview (download only).

Credits

Shahariar

Shahariar

74 projects • 265 followers
"What Kills a 'Great life' is a 'Good Life', which is Living a Life Inside While Loop"

Comments