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 07:55:08 -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 06TElQRe020625; Wed, 29 Jul 2020 10:47:40 -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 06TElPOZ020622 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 29 Jul 2020 10:47:25 -0400 Received: from w92exedge4.exchange.mit.edu (W92EXEDGE4.EXCHANGE.MIT.EDU [18.7.73.16]) by outgoing-exchange-3.mit.edu (8.14.7/8.12.4) with ESMTP id 06TEmqTn017009 for ; Wed, 29 Jul 2020 10:49:26 -0400 Received: from w92expo10.exchange.mit.edu (18.7.74.64) by w92exedge4.exchange.mit.edu (18.7.73.16) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Wed, 29 Jul 2020 10:46:27 -0400 Received: from oc11exhyb6.exchange.mit.edu (18.9.1.111) by w92expo10.exchange.mit.edu (18.7.74.64) with Microsoft SMTP Server (TLS) id 15.0.1365.1; Wed, 29 Jul 2020 10:46:55 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.101) by oc11exhyb6.exchange.mit.edu (18.9.1.111) with Microsoft SMTP Server (TLS) id 15.0.1395.4 via Frontend Transport; Wed, 29 Jul 2020 10:46:55 -0400 Received: from DM5PR2201CA0007.namprd22.prod.outlook.com (2603:10b6:4:14::17) by BN6PR0101MB2964.prod.exchangelabs.com (2603:10b6:405:2d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.22; Wed, 29 Jul 2020 14:46:53 +0000 Received: from DM3NAM03FT020.eop-NAM03.prod.protection.outlook.com (2603:10b6:4:14:cafe::46) by DM5PR2201CA0007.outlook.office365.com (2603:10b6:4:14::17) 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 14:46:53 +0000 Received: from mail-pl1-f179.google.com (209.85.214.179) by DM3NAM03FT020.mail.protection.outlook.com (10.152.82.193) 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 14:46:53 +0000 Received: by mail-pl1-f179.google.com with SMTP id q17so11871429pls.9 for ; Wed, 29 Jul 2020 07:46:53 -0700 (PDT) From: James Burkart To: Microcontroller discussion list - Public. Sender: "piclist-bounces@mit.edu" Date: Wed, 29 Jul 2020 07:46:41 -0700 Subject: Re: [PIC] How to properly set PWM duty cycle Thread-Topic: [PIC] How to properly set PWM duty cycle Thread-Index: AdZluEDaByw2ThlhT5CYzPEvOSLL8w== 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: TempError 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=xNUYCFVCeIDvwr4abGkgrLoC13GiXy92iIweb280k3s=; b=hFQ/mYsuQKhs4q1SAzC6klzY7MYwXV2XPgj/3AumdsRLt3j+wBZC1Far/T0t2CYrHo 1vOybeJUSka2xviIs5jaDoryu/N5bHxw86UXK2X2/qC5WArNB840P/Mw7MhIgb8YloAk zoOpQ8NewI4KoXuihMvZTS8PqTt5kaDlQLM0FcDy8lNNB1bw57XF+U29O6faBBDUOQsD AlQrTUq/o+YV+gkQE9eNQ35EfR41x2aQYOcisaU4L8QxDVw2LJXbr2WVl8ZV0pGJ/Ovy HHGW0Ntl67j7PByOijU/CNgzZyAg0nS00PBvlH09R5ZmEksF/wL/JGgYEwgmaysjcqV8 jBPg== authentication-results: spf=none (sender IP is 209.85.214.179) 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:90b:3010:: with SMTP id hg16mr9998780pjb.69.1596034012144; Wed, 29 Jul 2020 07:46:52 -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 Thanks, Nicola. Human bean, it's a compliment. It is someone who, though might be a little jaded, is willing to help someone for the greater good. On Wed, Jul 29, 2020, 8:04 AM Nicola Perotto wrote: > Hi James, > > On 29/07/2020 14:35, James Burkart wrote: > > "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. > My bad, I misunderstood the sentence, I speak better Asm than English ;-) > > > > > What library? I did say I'm using MCC generated functions. Do you mean > you > > would like to know what version of MCC? > I never used MCC so for me is not significant but for other people can be= : > version of tools and libraries is often important. > > > > > > 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. > This was another missing information item :-) > With PWM you have to check: > - there is "something" in the pin; > - the frequency is correct or if it's wrong is an integer (sub-)multiple > of > required frequency; > - the duty is correct. > If something is wrong the first step is to obtain a pwm, with a fixed and > known > duct cycle. > Than I work with frequency, usually with a very minimal program to exclud= e > other > causes. > > > 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!! > Bean, beam... maybe but human?!?!?! Are you sure? ;-) > Happy to help > Nicola > > > > > > > -- 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 detail= s! > >> 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 PW= M > >> 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 puls= e > >>> 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* > >> -- > >> > >> 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 > >> > > -- > > 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 .