Received: from PCH.mit.edu (18.7.21.50) by mail.efplus.com (192.168.0.8) with Microsoft SMTP Server (TLS) id 8.3.485.1; Wed, 29 Jul 2020 05:47:31 -0700 Received: from PCH.MIT.EDU (localhost.localdomain [127.0.0.1]) by PCH.mit.edu (8.14.7/8.12.8) with ESMTP id 06TCc9uS001133; Wed, 29 Jul 2020 08:38:47 -0400 Received: from outgoing-exchange-7.mit.edu (OUTGOING-EXCHANGE-7.MIT.EDU [18.9.28.58]) by PCH.mit.edu (8.14.7/8.12.8) with ESMTP id 06TCZbWC000833 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 29 Jul 2020 08:35:38 -0400 Received: from w92exedge4.exchange.mit.edu (W92EXEDGE4.EXCHANGE.MIT.EDU [18.7.73.16]) by outgoing-exchange-7.mit.edu (8.14.7/8.12.4) with ESMTP id 06TCXmvx000505 for ; Wed, 29 Jul 2020 08:33:50 -0400 Received: from w92exhyb4.exchange.mit.edu (18.7.71.74) by w92exedge4.exchange.mit.edu (18.7.73.16) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Wed, 29 Jul 2020 08:35:08 -0400 Received: from oc11exhyb1.exchange.mit.edu (18.9.1.60) by w92exhyb4.exchange.mit.edu (18.7.71.74) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 29 Jul 2020 08:35:36 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.174) by oc11exhyb1.exchange.mit.edu (18.9.1.60) with Microsoft SMTP Server (TLS) id 15.0.1395.4 via Frontend Transport; Wed, 29 Jul 2020 08:35:36 -0400 Received: from DM6PR18CA0014.namprd18.prod.outlook.com (2603:10b6:5:15b::27) by CY4PR01MB3253.prod.exchangelabs.com (2603:10b6:903:eb::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Wed, 29 Jul 2020 12:35:35 +0000 Received: from DM3NAM03FT005.eop-NAM03.prod.protection.outlook.com (2603:10b6:5:15b:cafe::8) by DM6PR18CA0014.outlook.office365.com (2603:10b6:5:15b::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Wed, 29 Jul 2020 12:35:35 +0000 Received: from mail-pg1-f170.google.com (209.85.215.170) by DM3NAM03FT005.mail.protection.outlook.com (10.152.82.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.10 via Frontend Transport; Wed, 29 Jul 2020 12:35:34 +0000 Received: by mail-pg1-f170.google.com with SMTP id j19so14172662pgm.11 for ; Wed, 29 Jul 2020 05:35:34 -0700 (PDT) From: James Burkart To: Microcontroller discussion list - Public. Sender: "piclist-bounces@mit.edu" Date: Wed, 29 Jul 2020 05:35:22 -0700 Subject: Re: [PIC] How to properly set PWM duty cycle Thread-Topic: [PIC] How to properly set PWM duty cycle Thread-Index: AdZlpm1D5IqlIiEzSs64Gn326+xcFg== Message-ID: References: List-Help: List-Subscribe: , List-Unsubscribe: , In-Reply-To: Reply-To: Microcontroller discussion list - Public. Accept-Language: en-US X-MS-Exchange-Organization-AuthAs: Anonymous X-MS-Exchange-Organization-AuthSource: TS500.efplus4.local X-MS-Has-Attach: X-Auto-Response-Suppress: All X-MS-Exchange-Organization-SenderIdResult: Pass X-MS-Exchange-Organization-PRD: mit.edu X-MS-TNEF-Correlator: received-spf: None (protection.outlook.com: burkartstudios.com does not designate permitted sender hosts) dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=burkartstudios-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=j5IHosj6sZcQogldOBJsn65E319LEmTlTB/ppf3fBzc=; b=Sb6IXHWTNR2KbNTtaFyzZ0Y6oaHdzKtJ7QSqCt4j3VhiC9MBeEf2yaYv0ZQOH4iNr0 49mq/ds8h/P/Q+Pa2oRZOF8NW7QCBwZLwN5rNrh3jCSiuZgmKudGpFa3f+gqZBqCH6VV cp8MgL94HgQYRnodA/R4s+rs4yT2jPhLWh55lYxQdxHcCUJkmjLlSOumsoOBNiY0/BQK 2ijkwcj0uBLcve/9/IU58hgu0A1LUR/rHP0p1TFpR1Py/GZ/pVpVTvHsy2814TnByWeW C5pX6AgT4tFa3hoK4j4HmNqbe4eykEWplTGmHk0dF7ytq2IOak/2qA908HLIUuoAu9qR ZsIw== authentication-results: spf=none (sender IP is 209.85.215.170) smtp.mailfrom=burkartstudios.com; mit.edu; dkim=pass (signature was verified) header.d=burkartstudios-com.20150623.gappssmtp.com; mit.edu; dmarc=none action=none header.from=burkartstudios.com; errors-to: piclist-bounces@mit.edu list-id: "Microcontroller discussion list - Public." list-post: x-beenthere: piclist@mit.edu x-mailman-version: 2.1.6 x-received: by 2002:a62:7546:: with SMTP id q67mr12230317pfc.210.1596026133450; Wed, 29 Jul 2020 05:35:33 -0700 (PDT) x-topics: [PIC] x-content-filtered-by: Mailman/MimeDel 2.1.6 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 "What am I not getting?" Is very useful. It tells you that I don't understand, possibly not even enough to know what information you need to help me. What library? I did say I'm using MCC generated functions. Do you mean you would like to know what version of MCC? PR2 is calculated by MCC. I'll dig through the generated code and see what it is set to. There is something wrong with MCC: it's not showing the proper PWM frequency. My last question to the PIC list was about that problem. Thanks, Nicola, for pointing me in the right direction. You're a wonderful human bean!! -- James On Wed, Jul 29, 2020, 1:12 AM Nicola Perotto wrote: > Hi James, > find attached a small spreadsheet to do calculations. > It confirm (part of) your calculations. > I don't know the library you are using. > Some info are missing: > - code snippet, including PWM initialization > - PR2 value (the period is calculated from this, not the inverse), my > value is 155 > - "What am I not getting?" is actually useless... describe with details! > Regards > Nicola > > > On 29/07/2020 06:07, James Burkart wrote: > > Hey, everyone! > > > > I am trying to figure out how to properly set the duty cycle for a PWM > on a > > PIC16F1503. I'm sure I am missing something obvious. > > > > System clock is the internal oscillator at 16MHz. > > TMR2 prescaler is 1:64, period is set to 2.496 ms. > > This gives the PWM a 9-bit resolution. > > > > The PWM frequency is 400 Hz. My goal is to be able to adjust the pulse > > width from 1 ms to 2 ms (controlling an ESC). > > > > I'm using the MCC generated function: > > > > void PWM2_LoadDutyValue(uint16_t dutyValue) > > > > I was assuming that making dutyValue 512 would give me a 100% duty cycl= e, > > instead I get a duty cycle of around 82%. > > A dutyValue of 624 gets me 100%, 312 gets me 50%. > > > > What am I not getting? > > > > -- > > Sincerely, > > > > James Burkart > > *925.667.7175* > > -- > > Nicola Perotto - NP Engineering > Sistemi Informatici ed Elettronici > skype: nicolap > > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .