Phase Shifting a PWM signal - Page 1
Forum section: electronics / general

author: Puffie40
author_rank: Regular Contributor
timestamp: April 13, 2021, 05:53:03 pm
content: I have an 24VAC Motor I am trying to drive with a microcontroller. The motor windings originally used a capacitor to phase shift the signal (Im guessing this would be called a "Run Capacitor").The motor is quite heavily geared, so it only needs to run at one speed, but it does need to be able to change rotation direction. I figure two PWM Signals from a PIC16f15245 to a L298 can drive it, but how would I phase shift those signals in the code?

author: Ian.M
author_rank: Super Contributor
timestamp: April 13, 2021, 06:55:24 pm
content: You wouldn't. The CCP modules in that PIC are the 'classic' 10 bit PWM ones and it only has a single timer that can drive them in PWM mode, so offset PWM isn't possible.You *could* do offset waveform generation using two CCP modules in output compare mode, with a free-running common timer 1 timebase, but that involves doing 16 bit maths in an ISR for each edge to calculate how much to add to the channels CCPRx register to set when the hardware will next flip the output pin.Maybe look at PICs with motor control 16 bit PWM peripherals?SeeTB3137 High-Precision 16-Bit PWM Technical BriefThe alternative that your PIC *might* just be capable of would be software DDS to generate quadrature sinewaves with the PWM module running as fast as you can while still getting enough resolution to output them. However if you don't want a lot of messing around with high current dual rail supplies, you'll actually need three PWM channels for the three motor terminals.

author: Puffie40
author_rank: Regular Contributor
timestamp: April 13, 2021, 07:25:05 pm
content: Oof! Looking around on the internet made me suspect that the PIC I chose wouldn't be able to do it , so that's why I wrote the post. Thank you for that.It looks like switching over to a PIC16F1579 would be not have much impact on the design I have. I'll start poking though the datasheet.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 13, 2021, 08:52:34 pm
content: Not sure what your MCU would have to do apart from driving the motor, but if it's its main task, you could certainly generate the signals by bit banging instead of using a PWM peripheral, and thus generate exactly what you want.

author: Puffie40
author_rank: Regular Contributor
timestamp: April 13, 2021, 09:44:39 pm
content: Quote from: SiliconWizard on April 13, 2021, 08:52:34 pmThe MCU's only other tasks is to monitor two limit switches and an external control switch. The other pins are driving the L298 - two enables, four pwm outputs.so the total is 3 digital inputs, 2 digital outputs, and 4 PWM pins.I could Bit-Bang it - The motor only needs 50-60hz to run, so a fairly simple MCU could do it. I do want to try figure these PWM modules out, though.

author: DavidAlfa
author_rank: Super Contributor
timestamp: April 13, 2021, 09:45:32 pm
content: What PWM frequency? Are you going to drive the motor with simple square wave? Or pseudo sine wave?If it's simple square wave drive, that's easy, just start PWM1, wait the time that corresponds to the phase required, start PWM2.If it's pesudo sine wave, then update two different pwm timers in their own interrupts.I understand that the phase shift is fixed. So you only have to make the 360º sine wave.Make a table with pwm values, and a "phase" variable.PWM1 interrupts takes next PWM value and updates the phase.PWM2 interrupts reads the phase and sets the PWM value adding the wanted shift.I know the pictures are 3-phase but it's the same.

author: Puffie40
author_rank: Regular Contributor
timestamp: April 13, 2021, 09:53:25 pm
content: Quote from: DavidAlfa on April 13, 2021, 09:45:32 pmThe parameters I have is a 60Hz (16.7ms) simple square wave with a %50 duty cycle. A square wave is not the best for the motor, but at the moment it would be the simplest to set up for a guy who is still shaking the rust off his education

author: DavidAlfa
author_rank: Super Contributor
timestamp: April 13, 2021, 10:08:34 pm
content: Then it's super easy!Assuming you want 90º shift:- Set the PWM1 and PWM2 timers for those 16.7mS. The period counter will be "x". But don't start any yet.- Set the PWM values as 50% of the period.- Start PWM1- You know the timer counter for 90º will be "x/4". So keep polling the PWM1 counter. When it reaches that value, start PWM2.Now both PWM are running with a 90º phase shift.Also, there are pic16/pic18 with motor-specific hardware. You know, complementary PWM generation, dead time, fault detection pin (To latch all PWM outputs low without user intevention).

author: james_s
author_rank: Super Contributor
timestamp: April 14, 2021, 12:07:16 am
content: Can you just use the original capacitor with a relay to select which winding is fed through the capacitor? It might also work to use an inductor to create a lag and select between the capacitor and inductor to change direction, I've never tried that so I don't know if it would actually work though.