cancel
Showing results for 
Search instead for 
Did you mean: 

Code translation

ted korczak
Associate III
Posted on June 11, 2018 at 08:37

Hi

How to change arduino uno code to STM32F103

void setup(){ pinMode(9,OUTPUT); pinMode(10,OUTPUT); TCCR1B = (1<<WGM13)|(1<<CS10);  TCCR1A = (1<<COM1A1)|(1<<COM1B1)|(1<<COM1B0);  TIMSK1 = 1<<TOIE1; ICR1=511;  OCR1B=0; }   ISR (TIMER1_OVF_vect) { static uint8_t  n=0; OCR1A =  OCR1B= sine_wave[n]; n++; }  void loop(){ }

1 ACCEPTED SOLUTION

Accepted Solutions
henry.dick
Senior II
Posted on June 11, 2018 at 20:09

Don't look at individual lines of code but blocks of code and ask yourself what those blocks are trying to do.

After that implement the functionality on your new target.

View solution in original post

4 REPLIES 4
Posted on June 11, 2018 at 20:06

You'd be better starting with what you're trying to achieve, and re-implement.

Set up clocks and pins

Program periodicity of TIM

Set up circular DMA to point to Sine Wave table, and configure TIM/DMA to update pulse width at each period update.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
henry.dick
Senior II
Posted on June 11, 2018 at 20:09

Don't look at individual lines of code but blocks of code and ask yourself what those blocks are trying to do.

After that implement the functionality on your new target.

ted korczak
Associate III
Posted on June 11, 2018 at 22:25

I am trying to modify simple sine wave generator for stm32f103, post # 21, click on - показать код

http://arduino.ru/forum/programmirovanie/shim-sinusoida#comment-152231

ted korczak
Associate III
Posted on June 12, 2018 at 05:25

Set up circular DMA to point to Sine Wave table

How to do that some links will help.

Similar code for STM32

HardwareTimer pwmtimer2(2); void setup() { pinMode(PA3, PWM); //Pin mode selected pwmtimer2.pause(); pwmtimer2.setPrescaleFactor(1); // Prescaler setup pwmtimer2.setOverflow(10000-1); // 256 ? pwmtimer2.setCompare(TIMER_CH4, 5000); // ? pwmtimer2.refresh(); pwmtimer2.resume(); } void loop() { } // How to tell to produce sine ?