Advertisement
pleasedontcode

"Sine PWM Setup" rev_01

Jan 20th, 2024
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Sine PWM Setup"
  13.     - Source Code compiled for: Arduino Mega
  14.     - Source Code created on: 2024-01-20 11:19:13
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* 3 sine  pwm to inverter  with 120 degree phase */
  21.     /* shift change the  frequency  of output wave? */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF ANALOG INPUT PINS *****/
  32. const uint8_t j_Potentiometer_Vout_PIN_A0 = A0;
  33. const uint8_t j_Potentiometer_Vout_PIN_A1 = A1;
  34.  
  35. // Constants for PWM output pins
  36. const uint8_t PWM_PIN_1 = 2;
  37. const uint8_t PWM_PIN_2 = 3;
  38. const uint8_t PWM_PIN_3 = 4;
  39.  
  40. void setup(void)
  41. {
  42.   // put your setup code here, to run once:
  43.  
  44.   /* 3 sine pwm to inverter with 120 degree phase shift */
  45.  
  46.   // Configure analog input pins as inputs
  47.   pinMode(j_Potentiometer_Vout_PIN_A0, INPUT);
  48.   pinMode(j_Potentiometer_Vout_PIN_A1, INPUT);
  49.  
  50.   // Configure PWM output pins as outputs
  51.   pinMode(PWM_PIN_1, OUTPUT);
  52.   pinMode(PWM_PIN_2, OUTPUT);
  53.   pinMode(PWM_PIN_3, OUTPUT);
  54. }
  55.  
  56. void loop(void)
  57. {
  58.   // put your main code here, to run repeatedly:
  59.  
  60.   /* change the frequency of output wave? */
  61.  
  62.   // Read the potentiometer values
  63.   int potValue1 = analogRead(j_Potentiometer_Vout_PIN_A0);
  64.   int potValue2 = analogRead(j_Potentiometer_Vout_PIN_A1);
  65.  
  66.   // Convert potentiometer values to PWM duty cycles (0-255 range)
  67.   int dutyCycle1 = map(potValue1, 0, 1023, 0, 255);
  68.   int dutyCycle2 = map(potValue2, 0, 1023, 0, 255);
  69.  
  70.   // Set the PWM duty cycles for the output pins
  71.   analogWrite(PWM_PIN_1, dutyCycle1);
  72.   analogWrite(PWM_PIN_2, dutyCycle2);
  73.   analogWrite(PWM_PIN_3, dutyCycle1 + dutyCycle2);
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement