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; Tue, 28 Jul 2020 21:16:33 -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 06T48J90024921; Wed, 29 Jul 2020 00:09:03 -0400 Received: from outgoing-exchange-3.mit.edu (OUTGOING-EXCHANGE-3.MIT.EDU [18.9.28.13]) by PCH.mit.edu (8.14.7/8.12.8) with ESMTP id 06T48HA3024918 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 29 Jul 2020 00:08:17 -0400 Received: from oc11exedge1.exchange.mit.edu (OC11EXEDGE1.EXCHANGE.MIT.EDU [18.9.3.17]) by outgoing-exchange-3.mit.edu (8.14.7/8.12.4) with ESMTP id 06T4AIXd006857 for ; Wed, 29 Jul 2020 00:10:18 -0400 Received: from oc11expo13.exchange.mit.edu (18.9.4.18) by oc11exedge1.exchange.mit.edu (18.9.3.17) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Wed, 29 Jul 2020 00:07:52 -0400 Received: from oc11exhyb2.exchange.mit.edu (18.9.1.98) by oc11expo13.exchange.mit.edu (18.9.4.18) with Microsoft SMTP Server (TLS) id 15.0.1365.1; Wed, 29 Jul 2020 00:08:16 -0400 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (104.47.37.53) by oc11exhyb2.exchange.mit.edu (18.9.1.98) with Microsoft SMTP Server (TLS) id 15.0.1395.4 via Frontend Transport; Wed, 29 Jul 2020 00:08:16 -0400 Received: from DM5PR07CA0058.namprd07.prod.outlook.com (2603:10b6:4:ad::23) by BYAPR01MB4790.prod.exchangelabs.com (2603:10b6:a03:86::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23; Wed, 29 Jul 2020 04:08:15 +0000 Received: from DM3NAM03FT053.eop-NAM03.prod.protection.outlook.com (2603:10b6:4:ad:cafe::9) by DM5PR07CA0058.outlook.office365.com (2603:10b6:4:ad::23) 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 04:08:14 +0000 Received: from mail-pj1-f46.google.com (209.85.216.46) by DM3NAM03FT053.mail.protection.outlook.com (10.152.83.181) 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 04:08:14 +0000 Received: by mail-pj1-f46.google.com with SMTP id f9so1400374pju.4 for ; Tue, 28 Jul 2020 21:08:14 -0700 (PDT) From: James Burkart To: Microcontroller discussion list - Public. Sender: "piclist-bounces@mit.edu" Date: Tue, 28 Jul 2020 21:07:37 -0700 Subject: [PIC] How to properly set PWM duty cycle Thread-Topic: [PIC] How to properly set PWM duty cycle Thread-Index: AdZlXwtN9dBUgLQfRByzPPYj+daukg== Message-ID: List-Help: List-Subscribe: , List-Unsubscribe: , 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:from:date:message-id:subject:to; bh=yi7W9NCiMtHqdJ/EOyxFtPAzYBXNO/1Z7Ff0PIVFsVo=; b=LkIXS6eazGGZHziZ0oWXFi6t5cMiD341u/BZJt/w37dBCqoFo4gHQfvGDZzF6Ctba+ JngW661hs6+MUzgEQkMUzwfAxUF+Dc7HoFP7m0ewnf0LpGFrQVUQEIprIAEXwegrvMrT 1L9qWLUZykCIZWlJA28RklYS/8B2hc83wRu/F0HaMnbwGKRJtnXrajAaL7rfoOzUlgyP /KAV9NPHUeTnQ3iIL814rZJtkQGpq+m8G4L4F4+sSAOlPgiSrz9Mz0naoAzvXcefm9GP Y6HKc8fbLbMLZeNgj2okw6F+j3w/WgTgFt7k8TYEc1lJC+ETP0JipxeQ6mMZicnJ3vvC RvQg== authentication-results: spf=none (sender IP is 209.85.216.46) 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:a17:902:7484:: with SMTP id h4mr11612237pll.139.1595995693216; Tue, 28 Jul 2020 21:08:13 -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 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 cycle, 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* --=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 .