Ticker can not be ticking

Hi, I want to generate an voltage output like 100khz like this.

Problem 1: On the STM32F103ZC my program above works down to 19us. But fails when I set it to 18us.

class LedKit {
  LedKit(PinName led_dac);
  void turn_on();

  void flip();
  AnalogOut _led_vout;
  Ticker   _ticker;
  bool _flag{false};
  uint16_t _voltage{0};
  uint16_t voltage{0};
LedKit::LedKit(PinName led_dac)
  : _led_vout(led_dac) {
  _voltage =0x01ff;
void LedKit::flip() {
  _flag = !_flag;
  voltage = (_flag) ? _voltage : 0;
  //_led_vout.write_u16(voltage);//AnalogOut _led_vout;
void LedKit::turn_on() { _ticker.attach(callback(this, &LedKit::flip), 20us); }

Problem 2: When i add the _led_vout.write_u16(voltage), it doesn’t work anymore.
I want to solve problem 1, thanks very much.


Because rest of code is not visible, what about volatile key word for voltage and _voltage variables (seem be global).
Another posibility is different data types of varibles and parametrs.

About time issue i am not sure but maybe it is limit for this mcu and is permanently in ISR.

I do not know exact usage but is not PwmOut better for this?

BR, Jan

Thanks very much. I want to generate a 100khz square wave with a certain voltage. So with no hardware changed, the "ticker + dac " or “dma + dac” mode can work. The “pwm+dac” mode can work also with “hardware analog switch”.

What about using a PWM, adjusting the duty cycle, and feeding it through an RC filter to average it out into a voltage?

Oh oops nvm you mean that the amplitude of the square wave needs to be configurable, but it should still be a square wave?

Yeah I think the easiest way to do that would be to use a DAC to output a constant voltage, and then switch that voltage on and off via e.g. FET transistors or an analog switch IC.