Page 1 of 1

PWM in the MIAC V2

Posted: Wed Jul 19, 2017 5:39 pm
by go233
Hello can I have a bit of help on how to set the PWM of my MIAC V2, please?
So I need to generate a square wave variable from 200Hz to 2Khz ish, and I need to vary the duty cycle from 50% to 90% ish.
what would you set in the PWM macro parameters?
ChangePeriod
SetDutyCycle

So when I want to generate the square waveform on the transistor at output A I will write the following instructions in flowcode 6:
OutputOn(1)
ChangePeriod (UINT, INT)
SetDutyCycle (BYTE)
Enable

and the MIAC should generate this waveform continuously, is it correct?
Thanks
Giovanni

Re: PWM in the MIAC V2

Posted: Wed Jul 19, 2017 7:15 pm
by LeighM
Hi,
Have a look at the examples in this thread
http://www.matrixtsl.com/mmforums/viewt ... 28&t=19006
If that does not help let me know and I will boot up Flowcode tomorrow.

Re: PWM in the MIAC V2

Posted: Thu Jul 20, 2017 1:38 pm
by go233
I cannot get the duty cycle and the frequency to change using ChangePeriod and SetDutyCycle!
I need to generate 200Hz to 2Khz ish, and I need to vary the duty cycle from 50% to 90% ish.
I have attached my program and a picture from the oscilloscope: I alwaus get the same picture regardless the values of INT Prescaler abd BYTE duty (I leave UINT Period = 255) I tried.
Giovanni

Re: PWM in the MIAC V2

Posted: Fri Jul 21, 2017 2:44 pm
by Steve
Your program does not appear to use the PWM component. You need to add this and use its functions to set the PWM duty.

Have you looked at the Flowcode programs in that thread Leigh suggested? Those are for the dsPIC MIAC v3.

There are also examples for the MIAC PIC (i.e. v2) here: http://www.matrixtsl.com/miac/resources/

In particular, the MOTOR_5 example uses PWM.

Re: PWM in the MIAC V2

Posted: Sat Jul 22, 2017 8:24 pm
by go233
Yes I can change the duty cycle no problem.
But
I have set ChangePeriod (255, INT)
I have noticed that not all the values are accepted by the prescaler:
for instance 1,4, 16 are accepted and the change the output frequency.
Could you tell me which number are accepted by the prescaler please?
Thanks
Giovanni

Re: PWM in the MIAC V2

Posted: Sun Jul 23, 2017 10:10 am
by go233
I looked at the datasheet of the 18F4455 and I have just realized that the prescaler can divide for 1 4 16.
So the minimum frequency can be freq of the clock / 16.
I guess I cannot change the clock frequency.....or I can?

Re: PWM in the MIAC V2

Posted: Mon Jul 24, 2017 8:32 am
by Steve
The clock frequency within Flowcode should equal the clock frequency used by your hardware. So you can't just change that value and expect it to work.

But you can use a different clock speed in your hardware (e.g. a slower crystal or using the internal oscillator options).

Re: PWM in the MIAC V2

Posted: Mon Jul 24, 2017 11:58 am
by go233
how can I change the clock frequency of the micro inside my MIAC V2?
and
could you confirm the prescaler values that I can use, please?
Thanks
Giovanni

Re: PWM in the MIAC V2

Posted: Mon Jul 24, 2017 1:07 pm
by LeighM
Hi,
The clock could be changed but would cause issues elsewhere.
As the PWM component Prescaler values indicate, yes, only a prescaler of 1, 4 or 16 can be used.
So the slowest CCP clock is 750KHz.
If you use a 10 bit value for the Period and the Duty (using SetDutyCycle10Bit) you could get the frequency down to about 730Hz

Maybe you could use the PWM component down to say 700Hz, then use a bit-banged loop with timed delays for frequencies below that?

EDIT:
Ben tells me that the 10 bit support on this PIC device is not that simple, so the above is not quite true,
you are best to stick with the 8 bit period for hardware PWM, which will get you down to about 3KHz
Other than that you will need to use the timed loops, or interrupts, as above.

Note to self: read the device datasheet :lol:

Re: PWM in the MIAC V2

Posted: Tue Jul 25, 2017 10:54 am
by go233
I think I will use the 8 bit period for hardware PWM, which is gets me an output of about 3KHz.
Thanks
Giovanni