Proplem at pwm signal from arduino iot cloud ,using ARDUINO R4 WIFI

Hi,

After applying this code get 10KHZ pwm, with some modifications to make it compatible with my main code using AI tools, I achieved good results on all pins that were supposed to generate a 10kHz PWM signal when using the Arduino IDE. However, the problem started when I used this code in the Arduino Cloud Editor.

Initially, I encountered error messages related to libraries. I fixed this by adding the necessary additional libraries. Then, I incorporated the necessary code lines to establish a Wi-Fi connection. Additionally, I added gauges to the dashboard and selected the variables I wanted to display on them, as my power electronics project includes sensors. Finally, I uploaded the code, and it worked – the sensors provided values on the dashboard gauges. However, when I connected my oscilloscope to the PWM pins, I did not get any readings.
this is the code

#include <CBOR.h>
#include <CBORArray.h>
#include <CBORComposed.h>
#include <CBORPair.h>
#include <YACL.h>
#include <PWMrelay.h>
#include <wire_asukiaaa.h>
#include <wire_asukiaaa_template.hpp>
#include "thingProperties.h"
#include <pwm.h>
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal.h>
#include <Wire.h> 
#define PWM_BUCK_PIN 3 // pwm mosfet buck 10KHz
#define PWM_BOOST_PIN 5 // pwm mosfet boost 10KHz
#define PWM_BUCK_ENABLE_PIN 6 // on/off driver mosfet buck
#define PWM_BOOST_ENABLE_PIN 9 // on/off driver mosfet boost
#define TURN_ON_MOSFETS_BUCK digitalWrite(PWM_BUCK_ENABLE_PIN, HIGH) 
#define TURN_OFF_MOSFETS_BUCK digitalWrite(PWM_BUCK_ENABLE_PIN, LOW) 
#define TURN_ON_MOSFETS_BOOST digitalWrite(PWM_BOOST_ENABLE_PIN, HIGH)
#define TURN_OFF_MOSFETS_BOOST digitalWrite(PWM_BOOST_ENABLE_PIN, LOW)
//---------- variables -------
/* VARIABLES
..........................
..........................*/
//-----------------------------------
enum charger_mode {off, on, bulk_mode, abs_mode, float_mode} charger; // enumerated variables for switch case sub-programs
//---------------------------------------------
PwmOut pwmBuck(PWM_BUCK_PIN);
PwmOut pwmBoost(PWM_BOOST_PIN);
//---------- MAIN SETUP -------------------------//
void setup()
{
 Serial.begin(9600);
 delay(1500);
 initProperties();// from iot cloud 
 ArduinoCloud.begin(ArduinoIoTPreferredConnection); // from iot cloud
 // initialize the pins output
 pinMode(3, OUTPUT);//for arduino uno R4 wifi
 /* ALSO FOR 5 , 6 AND 9 */
  // Initialize PWM signal for buck and boost pins
 pwmBuck.begin(10000.0f, 50.0f); // 10kHz frequency, 50% duty cycle
 pwmBoost.begin(10000.0f, 50.0f); // 10kHz frequency, 50% duty cycle
 //-------------------------------------------------------------------------------------------------------
 setDebugMessageLevel(2);// from iot cloud
 ArduinoCloud.printDebugInfo();// from iot cloud
}
//------------ MAIN LOOP ------------------------//
void loop()
{
 ArduinoCloud.update();// from iot cloud
 CHARGING_MODE(); // sub-program for charging
 /*OTHER SUB-PROGRAMS..................*/
}
//------------ SENSING MODE ---------------------//
void SENSING_MODE()
{
 for(int i = 0; i < 100; i++){
   temp1=analogRead(A0); // read the analog pin for sensing current from solar panel
   sum1 += temp1; // store sum for averaging
   /*SAME CODE TO PIN 1 ,2 AND 3 */
   }
//............................
/*CODE LINES FOR SCALLING THE VALUE OF SENSORS*/
//............................
}
//------------- CHARGING MODE -------------------//
void CHARGING_MODE() 
{

    switch (charger) {
        //============ ON MODE ========//
        case on:
            if (/*SOME CONDITIONS*/) {
              //VARIABLES GET CHANGED ......
              //..............................
                set_pwm();
            break;
            // CONTINUE FOR OTHER CASES 
            /*......................
            ..*/

}
//---------------- PWM Setting ------------------//
void set_pwm()
{
  PWM_BUCK = PWM * 8;
  PWM_BOOST = 800 - PWM_BUCK; // 800 represent 100% duty cycle ICR1 = 800
  // Convert percentage duty cycle to pulse width (0-100% to 0-800)
  uint16_t pwmBuckValue = map(PWM_BUCK, 0, 100, 0, 800);
  uint16_t pwmBoostValue = map(PWM_BOOST, 0, 100, 0, 800);
  pwmBuck.pulseWidth_us(pwmBuckValue);  // Set pulse width for buck mode
  pwmBoost.pulseWidth_us(pwmBoostValue); // Set pulse width for boost mode
}

The post was edited after taking advice from @ptillisch , anyone want a picture of the circuit and the whole code, tell me, and I will post it here for further explanations.

Hi @yah_1. This is quite a complex program. My advice is to create a demonstration program that contains only the absolute minimum of code required to produce the fault. Doing this will make the situation easier to understand by removing all irrelevant complexity from the system.

I find that often by the time I have completed this work the cause of the fault has become clear to me. Even if it doesn't, you can then share this minimal, reproducible, verifiable example (MCVE) here on the forum. It will be of value to the helpers here.

Thank you,I appreciate your response, sorry I'm just a beginner at FORUM, but I will try to make it simple.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.