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
PWM in the MIAC V2
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
Re: PWM in the MIAC V2
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.
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
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
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
- Attachments
-
- pwm.fcfx
- (4.42 KiB) Downloaded 381 times
- Steve
- Matrix Staff
- Posts: 3429
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: PWM in the MIAC V2
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.
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
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
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
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?
So the minimum frequency can be freq of the clock / 16.
I guess I cannot change the clock frequency.....or I can?
- Steve
- Matrix Staff
- Posts: 3429
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: PWM in the MIAC V2
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).
But you can use a different clock speed in your hardware (e.g. a slower crystal or using the internal oscillator options).
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
Re: PWM in the MIAC V2
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
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