Using Output Compare

Create new topics, add your comment, remark, bugs...
Post Reply
jmednick
Posts: 3
Joined: Fri Mar 12, 2010 9:02 pm

Using Output Compare

Post by jmednick » Tue Jun 29, 2010 9:59 pm

Hello Lubin,

I just wanted to confirm that I'm using the OC Output Compare block correctly...

First off, it seems like OC1max is a constant that is relevant to the chip. Is there a way I inherit it from the chip, because just making a constant block called [OC1max] does not work.

Additionally, if I wanted to set up a 50% wave at 2 KHz, then I would need Max / Channel to be set to 0.0005 and up would be (0.00025 / 0.0005 )* OC1max?

What do I set Period to, as it needs an integer input?

Thanks!

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

Re: Using Output Compare

Post by LubinKerhuel » Wed Jun 30, 2010 8:44 am

Hello Jared
jmednick wrote:First off, it seems like OC1max is a constant that is relevant to the chip. Is there a way I inherit it from the chip, because just making a constant block called [OC1max] does not work.
OC1max is relevant to the internal chip frequency (typically depending on quartz and PLL used).
the dsPIC blockset evaluate this variable in the MATLAB workspace. Type "who" at matlab prompt to list all variable. Get the variable value typing its name "OC1max" (case sensitive).
There are two OC blocks :
OC hardware that create one variable OCmax.
OC that create variables OC(x)max with x, corresponding to each channel (1, 2 3 or 4)
==> use the correct one.
jmednick wrote:Additionally, if I wanted to set up a 50% wave at 2 KHz, then I would need Max / Channel to be set to 0.0005 and up would be (0.00025 / 0.0005 )* OC1max?
That's correct. The OC(x)max value should be high enough (otherwise, you will not get a correct precision, workaround would be to increase the chip internal MIPS through quartz or PLL)
As you must use an integer value, roundoff result : round((0.00025 / 0.0005 )* OC1max).
Period must be set at OC1max (In your case, period is fixed at OC1max, thus, you can remove the Period input from the block).

Please feel free to edit the wiki pages about OC blocks to make them better.

Lubin

Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests