Output Compare block - Behaviour at edges values for OC1max

Post Reply
Masaki
Posts: 12
Joined: Mon Aug 13, 2007 2:39 am
Location: Japan

Output Compare block - Behaviour at edges values for OC1max

Post by Masaki » Tue Feb 26, 2008 12:32 pm

I'm working on Output Compare block to make a PWM output and came across a strange
phenomena.

What I did was to connect a potentiometer to AN0 and a oscilloscope to OC1.
The potentiometer is hooked to +5V and GND.
I set MaxChannel of OC block to 1e-4, 2e-5,1e-5 to get 10kHz, 50kHz, 100kHz PWM signals.
Channels Input Type is set to be 10 to get variable Down duration.

When I turn the potentiometer in full swing, the PWM Down period varies between:
10kHz 500ns-100us
50kHz 500ns-20us
100kHz 500ns-10us.

OC1max value in each case is:
10kHz 3000
50kHz 600
100kHz 300.

What I think strange is that the pulse duration changes x2000, x400, x200 times.
These numbers should be the same as OC1max values, as they represent the maximum
allowable input to Output Capture block.

Why these difference happens? Is there any setting I miss?

Masaki

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: OC1max value in Output Compare block

Post by LubinKerhuel » Tue Feb 26, 2008 10:09 pm

Hi Masaki,

I upload the file I received by mail.
testan1.gif
testan1.gif (3.2 KiB) Viewed 11133 times
Masaki wrote:What I think strange is that the pulse duration changes x2000, x400, x200 times.
These numbers should be the same as OC1max values, as they represent the maximum
Allowable input to Output Capture block.
The pulse duration is the one defined in the block Output Compare dialog box. (If it is not the case, report it because it is a bug.)
The variable OC1max is a scalar value (uint16) that code for the max duration (max/channel) defined in the Output Compare dialog box.
This scalar value depends on the max duration (max/channel) set in the dialog box.

Few remarks about this model.
First, it is very useful to view data types.
In your case, I guess that after the first multiplication/division block, you get a double, and after the second multiplication block, you get a uint16 ?
I strongly advice to replace theses two multiplication blocks by one gain block with the value (OC1max/4095).
The output of this gain block should be a uint16.
The computation of the multiplication could be set to either uint16, or another more precise data type.
If you use only uint16 ; depending if OC1max/4095 is near an integer value or not consider using floor(OC1max/4095) to avoid higher result than OC1max. Example: OC1max/4095 = 2.7 ==> would be round to 3 if integer computation is chosen...

If I do not response to your question, please provide more details and upload the model.

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: OC1max value in Output Compare block

Post by LubinKerhuel » Wed Feb 27, 2008 9:54 pm

Masaki, I post the information from your mail here.
Problem_OutputCompare_fastEvents.png
Problem_OutputCompare_fastEvents.png (30.34 KiB) Viewed 11120 times
In each experiments, I set MaxChannel of OC block to 1e-4, 2e-5,1e-5 to get 10kHz, 50kHz, 100kHz PWM signals.
Channels Input Type is set to be 10 to get variable Down duration.

What I notice is that the ratio of min and max of Duration isn’t equal to OC1max in each frequency. For example, in case of 100kHz, min duration is 500nsec, max duration is 10usec. The ratio is 20, while OC1max is 300.

Does this make sense?
The Output Compare (OC) peripheral used as PWM output is not completely hardware driven. It means that a minimum time is required between two events : time for code execution. In your case of 33ns Down period (corresponding to 1/300
* 1/100000) the falling and rising edge are too close to each other. A minimum execution time for instruction being executed between two edges is necessary. In this case, from your data, this minimum time is about 500ns. This correspond to an input value for the OC block of 15. So, 15 is the minimum acceptable value for the Down input block. (the OC block act like as a saturation if you set value lower than 15).
Note that the same phenomena will appears as your input value get very close from the Periode (setting two edge very close)

If you require such a small down period, considere using a dsPIC with a motor PWM peripheral. The PWM peripheral is hardware driven and will work best on theses "edge" phenomena.

Masaki
Posts: 12
Joined: Mon Aug 13, 2007 2:39 am
Location: Japan

Re: Output Compare block - Behaviour at edges values for OC1max

Post by Masaki » Thu Feb 28, 2008 1:13 am

I understand the situation.
As my CPU is dsPIC30F3013 at Fcy=30MHz, it's supposed to handle PWM signal generation by interrupts.
As a result, it can only generate edges at every 500ns at its fastest speed.

If I switch my CPU to dsPIC30F4012 with motor control pins,
does your software support hardware PWM signal generation?

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: Output Compare block - Behaviour at edges values for OC1max

Post by LubinKerhuel » Sat Mar 08, 2008 4:28 pm

Masaki wrote:does your software support hardware PWM signal generation?
Yes, hardware PWM signal generation can be done using the "motor PWM peripheral"

Lubin

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests