Chat freely about anything...

User avatar
By rab
#31404
eriksl wrote:Replace this
Code: Select alluint8 pwm_duty_init[PWM_CHANNEL] = {0};

by this
Code: Select alluint32 pwm_duty_init[PWM_CHANNEL];

Or even better: uint32_t, but for that, you need to have the open esp sdk which has the headers fixed.


The sdk manual states that the pwm_duty parameter is an array of uint8s, but now you mention it the header file does say uint32. Has anyone pointed that out to Espressif to correct the documentation? Either way I have actually tried with uint32s (as I saw it that way in other sample code) and unfortunately the result was exactly the same. I'm not sure why you think using uint32_t would be any better.

eriksl wrote:The = {0} is pointless, because it will only initialise the first member. Make sure all of them get initialised properly, which can be only done in a loop, because the length of the array is dynamic (due to the #define).

That is incorrect. {0} will initialise all values in the array to 0.

eriksl wrote:Did I already mention that #defines are evil? That you should use either static const or enum's?

That's your preference, but there is nothing at all wrong with #defines in general or how they were used in the little code I posted. In all likely hood the compiler will produce the exact same code after optimisation, worse case scenario putting them in variables will just waste stack space.

eriksl wrote:Did I already mention that you should enable ALL possible warnings on gcc, and if you did, gcc would have warned about an incompatible pointer at this point?

It should have anyway by default, without a cast to tell it the difference was deliberate. It was originally uint32s and one of the last things I tried was to switch to uint8s, as per the manual, I may have coped and pasted a version that didn't actually compile anyway, oops.
User avatar
By eriksl
#31417 You may be very "smart", but it doesn't work. My code works, four PWM's simultanuously, no problem, with every SDK from 1.2 to 1.4.

The issue may very well be caused by something not directly related, for example if the SDK "core" gets called often enough. Many programmers don't see the relevance of that. Or for example a stack overflow.
User avatar
By rab
#31418
eriksl wrote:You may be very "smart", but it doesn't work. My code works, four PWM's simultanuously, no problem, with every SDK from 1.2 to 1.4.

I'm not quite sure what point you're making. Just because I'm more familiar with C and pointed out some facts about the language doesn't make it a competition. As you say it works for you and it doesn't for me and that's why I was asking in here. Your point about the uint8/uint32 type was quite valid, just unfortunately I had also tried with uint32 and had the same result.

eriksl wrote:The issue may very well be caused by something not directly related, for example if the SDK "core" gets called often enough. Many programmers don't see the relevance of that. Or for example a stack overflow.

I'm not really sure what you mean about the core getting called often enough. Unless you mean code that is occupying the processor too long and hence the watchdog reset, that's exactly what I'm seeing but it's not my code that's doing it. I suspect the problem is probably related to some third part component as I'm using Sming and so it's going to be difficult to get to the bottom of. Since this thread was about the same problem and didn't look like it involved Sming it seemed worth asking here first.