9 years, 7 months ago.

Phase Shift PWM in KL25z

Hi everybody,

I'm new at mbed and I'm using KL25z to make Robot that plays soccer. In our circuit design, we need two PWM signals phase shifted by 180° and I just didn't find a way to do this. I tried many libraries and I just had a satisfactory result changing SoftwarePWM library. I used the original one and other that I just changed the signal to start with zero and finish with one. But when I powered the KL25z using a battery the PWM weren't working. So I need to know why it's not working or another code or library to use.

my code it's really simple and works when the KL25z is plugged to the computer.

Code :

  1. include "mbed.h"
  2. include "SoftwarePWM.h"
  3. include "SoftwarePWM2.h"

SoftwarePWM1 ch1(PTC8); SoftwarePWM1 ch2(PTC9);

int main() {

ch1.Enable(50000, 100000); ch2.Enable(50000, 100000);

}

and the library:

  1. include "SoftwarePWM2.h"
  2. include "mbed.h"

SoftwarePWM2::SoftwarePWM2(PinName Pin) : SoftwarePWM2Pin(Pin) {}

void SoftwarePWM2::SetPosition(int Pos) { Position = Pos; }

void SoftwarePWM2::StartPulse() {

SoftwarePWM2Pin = 0; PulseStop.attach_us(this, &SoftwarePWM2::EndPulse, Position);

}

void SoftwarePWM2::EndPulse() { SoftwarePWM2Pin = 1; }

void SoftwarePWM2::Enable(int StartPos, int Period) { Position = StartPos; Pulse.attach_us(this, &SoftwarePWM2::StartPulse, Period); }

void SoftwarePWM2::Disable() { Pulse.detach(); }

Be the first to answer this question.