Creating a variable frequency and variable amplitude sine wave using pwm  - Page 1
Forum section: electronics / general

author: Jason key
author_rank: Newbie
timestamp: January 02, 2020, 07:13:56 pm
content: Hey everyone this is my first post. Im wondering if anyone herr can help with this. So im building a motor controller from scratch its my first big project. I want to try alternatives to field oriented control. And im having fun doing it. Im currently learning programming micros (rich subject) so this is my question and it may be a silly one . Ok so to produce a sine wave from a lookup array id isr at ech pulse and update the compare register .. however if i try to change the frequency aswell wont this have an effect on the pulse widths? How is this compensated for ? Or am i missing something really stuoid? Thanks for your input guys and gals ! :-)The reason for this is i have an idea similar to foc that might be a little bit more efficient so id like to implement it and do some tests. Any reading material on this subject would be greatly appreciated . Many thanks again!

author: Yansi
author_rank: Super Contributor
timestamp: January 02, 2020, 08:25:10 pm
content: Unlikely you have invented anything superior to FOC, if you have to ask how to implement a basic PWM modulator outputting a sinewave.By the way, for a three-phase drive, sinewave is NOT the waveform you need to appear on the output leg of the inverter. That would provide low modulation index.Search for for example: Third harmonic injection, sixty degree PWM or space vector modulation (SVPWM).If you want to learn about more efficient modulator, look for DTC (direct torque control), for example the Takahashi algorithm.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: January 03, 2020, 05:32:29 am
content: Quote from: Jason key on January 02, 2020, 07:13:56 pmUsually, the low frequency motor drive sine waves, are created by modulating the PWM frequency, with 50% giving 0V on all phases.if you want to vary both the frequency and amplitude the peak modulation depth sets the amplitude, and the rate of modulation sets the frequency.A question on the design, is what feedback & control do you plan to use ?For experiments, you could load a large Flash device up with many combinations of Frequency and modulation depth to load into the PWM - basically like a playback system.If you want to do this more 'live', with feedback, then a more powerful chip with multiplies would make your testing simpler, as it is fast enough to generate live sine modulation

author: Jason key
author_rank: Newbie
timestamp: January 03, 2020, 10:36:40 am
content: Tha ks yansi for the reading materia. Well im very new to microcontrollers. So yeah very useless at present only been teaching myself in free time for about 6 months so its all very new to me. I can see it in the wave forms what i want to do but its difficult for me to program a microcontroller at this stage to produce results i want. I will read up on this thanks so can you explain to me how a catiable frequency variable duty can be achieved. More so how to keep the duty cycle steady whilst changing the frequency? Thanks :-)

author: Jason key
author_rank: Newbie
timestamp: January 03, 2020, 10:43:55 am
content: Hi thanks for your reply. Well so far iv designed a 40kw inverter that can handle inductive loads. That has taken 6 months to complete so as not to destroy the igbts. So thats working. Im not sure weather i definately want to measure currents and iv tried an optical feedback position sensor. And iv recently brought a c2000 piccolo dev board which is like a half dsp half micro does sine on the fly i think.. im half way theu a course . I alreqdy program in c but never pn embedded. So im halfway thru a course learning embedded c and assembly. Very cool im enjoying it loads.

author: Yansi
author_rank: Super Contributor
timestamp: January 03, 2020, 10:46:48 am
content: If you are new to microcontrollers, forget variable frequency drives. Learn to work with microcontrollers for at least a year or two to gather experience and understanding, then try some advanced stuff like a VFD.And also forget the damn shitduino, it is not suitable by any means for designing even the most basic of a drive. There way more suitable microcontrollers, even very cheap and small ones, that have the proper perihperals and capabilities to support a design of a VFD.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: January 04, 2020, 01:49:41 am
content: Quote from: Jason key on January 03, 2020, 10:36:40 amThat's fairly simple, you look at the ON and OFF times and the ON/(ON+OFF) is the duty and 1/(ON+OFF) is the Frequency.ie you can scale both on and off times, and keep duty fixed, while varying frequency.

author: rstofer
author_rank: Super Contributor
timestamp: January 04, 2020, 02:53:41 am
content: Microchip has some great white papers on motor drives using PIC microcontrollers (of course). Many are for polyphase AC motors. Maybe spend some time searching over there.Maybe something like this will give you some ideas:http://ww1.microchip.com/downloads/cn/AppNotes/cn012129.pdf

author: NiHaoMike
author_rank: Super Contributor
timestamp: January 04, 2020, 04:12:40 am
content: There's a rather elaborate open source project for a motor drive based on a STM32.https://openinverter.org/docs/index.html%3Fen_home,3.html

author: Jason key
author_rank: Newbie
timestamp: January 04, 2020, 09:55:07 am
content: Yes yansi instarted on the arduino. Having no programming experience at the time. I actually found it a very usefull tool in realising the power of microcontrollers in a similar way a child would. So i started there. Then learnt c language. Then started to watch dr paz on you tube he used an arduino on the c level and now learning assembly as i like to know how things work so its nice to see past another layer of abstraction. So once iv finished the assembly part on the arduino. Im going to get theu dr saveks course of c using a ti launchlad as that dev board has a built in debugger and only costs 16 quid so that a bargain. I think itl be usefull to be able to see the registers etc. Im a quick learner picking this all up like a natural but still dont understand how you vary freqand amplitute simultaneously. I like jumping inot the deep end :-)

author: Jason key
author_rank: Newbie
timestamp: January 04, 2020, 10:04:48 am
content: Quote from: PCB.Wiz on January 04, 2020, 01:49:41 amAhh pcb wizz thanks i think youve answered my question so am i correct in saying on a bisc level that if i had frequecy x and a pwm of 50 percent and lowered the count on the timer compare thingy (excuse me im new to micros) that this would increase frquency but also increast the pwm as the toggle on cycles would stay the same but the cielinnof the counter would get less so the off time would decrease. Im reading that back and realise its a shit explanation. So the timer counts to a max level then resets but the compare match you can set at different levels to get different duty cycles. What i meant was if the timer compare match stays constant and you change the timer count to reset (the cieling as looking at it on the familiar timer graphs with triangles) then you would increase the frequency but also increase the duty cycle .. in fact if the timer reset was lowered to a value below the compare it would just stay on and stop toggling ? So the simple equation you posted keeps these in the correct ratio? I thought it must have had something to do with that.. in experience on my part.. yansi is right tho i need another 6 months to learn the basics. Thank you so much :-)

author: Jason key
author_rank: Newbie
timestamp: January 04, 2020, 10:06:08 am
content: Quote from: NiHaoMike on January 04, 2020, 04:12:40 am

author: Jason key
author_rank: Newbie
timestamp: January 04, 2020, 10:06:59 am
content: Quote from: NiHaoMike on January 04, 2020, 04:12:40 amYes i wil have to look into this thank you