Ticker Vs UART

02 Sep 2015

I am using the STM32F0 series, running on a Nucleo 072 board.

the Ticker works or the UART(through USB) works, but not both ???

  1. include "mbed.h"

Ticker toggle_led_ticker;

Serial pc(SERIAL_TX, SERIAL_RX); 9600 bauds, 8-bit data, no parity Serial pc(PA_2, PA_3); AnalogOut my_output(PA_4); DigitalOut myled(LED1);

  1. define PI (3.141592653589793238462)
  2. define AMPLITUDE (1.0) x * 3.3V
  3. define PHASE (PI * 1) 2*pi is one period
  4. define RANGE (4096/2) 12 bits DAC
  5. define OFFSET (4096/2) 12 bits DAC

Configuration for sinewave output

  1. define BUFFER_SIZE (360) uint16_t buffer[BUFFER_SIZE];

void calculate_sinewave(void); void toggle_led(void); void Ramp_DAC(void); void Dac_Sine_wave(void);

int Dac_Output =0; int Buffer_pointer =0;

int main() {

calculate_sinewave();

toggle_led_ticker.attach(&toggle_led, 0.000006); this is also output on Pin PA5, DAC2 5.75uSec is the fastest. =173.913kHz toggle_led_ticker.attach(&Ramp_DAC, 0.000006); toggle_led_ticker.attach(&Dac_Sine_wave, 0.000006); this stops the UART functioning in MBED

int i = 1; pc.printf("Hello World !\n"); while(1) { wait(0.1); pc.printf("This program runs since %d seconds.\n", i++); myled = !myled; } }

void toggle_led() { myled = !myled; }

void Ramp_DAC(void) { Dac_Output = Dac_Output + 2000; if(Dac_Output >4096) Dac_Output=0; if(Dac_Output >=3000) Dac_Output=0; my_output.write_u16(Dac_Output); my_output2.write_u16(Dac_Output); }

void Dac_Sine_wave(void) { Buffer_pointer ++; if (Buffer_pointer >359) { Buffer_pointer =0; toggle_led(); }

my_output.write_u16(buffer[Buffer_pointer]); my_output2.write_u16(buffer[Buffer_pointer]/2); }

Create the sinewave buffer void calculate_sinewave(void) { for (int i = 0; i < BUFFER_SIZE; i++) { double rads = (PI * i)/180.0; Convert degree in radian buffer[i] = (uint16_t)(AMPLITUDE * (RANGE * (cos(rads + PHASE))) + OFFSET); } }

02 Sep 2015

Can you start by adding code tags? (<<code>> and <</code>>).

Next if you think the UART doesn't work with ticker running, you can try just having those two included.

02 Sep 2015

Hi, Thanks for the pointer, I have done as you requested and found the issue.

I removed everything that was not part of the Ticker or Serial port code, it still didn't work. I slowed the ticker delay from 'as fast as possible' to 0.1 sec, then it worked. I reinstated all may other code, it worked, well done....

The solution is to run the ticker slower than 5.7uSec... I guess the other code wasn't getting any processor time.

now the next problem. I cant get the true serial port to output serial :( a new topic :)

Thanks again...