From owner-freebsd-arm@FreeBSD.ORG Thu May 22 18:51:19 2014 Return-Path: Delivered-To: freebsd-arm@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 325A9D7A for ; Thu, 22 May 2014 18:51:19 +0000 (UTC) Received: from mail-we0-x236.google.com (mail-we0-x236.google.com [IPv6:2a00:1450:400c:c03::236]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id BCF382F72 for ; Thu, 22 May 2014 18:51:18 +0000 (UTC) Received: by mail-we0-f182.google.com with SMTP id t60so3882365wes.13 for ; Thu, 22 May 2014 11:51:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Zb6k6dU7MEzTvCi0pvwb7GimzLRak8x1jLhieCEfX4w=; b=g4bkjGioAoNUYcRtiZ8pZaAWZznu/HMQp6NXDlzk3Xx/Oe58j6wsL2oRZVynjeduHT hrtLXLI2sw/Q3zUAF566jt1MsU2fSZQV6/J/+78s9lSfD3P/jEqNB8xA3MdCL8qF9dTH nhZqbzkMiRQs2LKknkPGEl+iV8jUYMKbCRs3snZ2hXk9VGORBbMhnQUr6kaDZEe5uHgX tu+ZZbrAWF7Mo7Uq57CpF7MiAtZ6FMW6Ri5+dbO96Vjs1qv+BvuNGCdhqUSPDWJLmT4C j+G/XNXoPFaJy+VEIEX0ruh93OGoZ2P4yFWy9Iev6On5gilYmqV8kbdVAQJXR2rHVH4p /ITQ== X-Received: by 10.194.179.9 with SMTP id dc9mr3761009wjc.74.1400784676904; Thu, 22 May 2014 11:51:16 -0700 (PDT) Received: from [192.168.113.40] (142.Red-83-56-26.staticIP.rima-tde.net. [83.56.26.142]) by mx.google.com with ESMTPSA id go1sm1735565wib.7.2014.05.22.11.51.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 May 2014 11:51:16 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Subject: Re: Beaglebone Black. PWM minimum frequency of 1.52KHz From: fabiodive In-Reply-To: Date: Thu, 22 May 2014 19:51:14 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Luiz Otavio O Souza X-Mailer: Apple Mail (2.1510) Cc: "freebsd-arm@freebsd.org" X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "Porting FreeBSD to ARM processors." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 May 2014 18:51:19 -0000 Hello Luiz, hello all my friends, Luiz, it is a real pleasure for me to hear you! I didn't try yet your work but I will do that tomorrow, actually your modifications sounds really well done. I will report here,=20 thank you! cheers, Fabio On May 22, 2014, at 15:19 , Luiz Otavio O Souza = wrote: > On 10 May 2014 08:56, fabiodive wrote: >> Hello, >>=20 >> PWM on Beaglebone Black >>=20 >> during my laboratory tests I was not able to setup a frequency = suitable for servo motors. >> I tried several times with many values but the results was always the = same. >> The minimal frequency I was able to achieve was 1.52 KHz. >> Also, I noticed odd results with the most of configuration values, in = this case >> I lost the PWM output signal. >>=20 >> I tried some combinations, measuring the results with an = oscilloscope, the period >> configuration key appears to loose its nanoseconds meaning beyond a = value: >=20 > Hi Fabio! >=20 > The PWM frequency is determined as SYSCLKOUT (100Mhz) / prescaler > settings / period. As the current code uses 1 for the prescaler and > the period is a 16bit value the lower frequency you can have is > actually 1.529Khz. >=20 >> # sysctl dev.am335x_pwm.1.period=3D1500 >> # sysctl dev.am335x_pwm.1.dutyA=3D300 >> result frequency: 66 KHz ->should be 666 KHz >> length of period: 15 us ->should be 1.5 us >> length of pulse: 2 us >=20 > As above, this is correct: 100Mhz / 1 / 1500 =3D 66Khz. >=20 >>=20 >> # sysctl dev.am335x_pwm.1.period=3D1500000 >> # sysctl dev.am335x_pwm.1.dutyA=3D10000 >> result frequency: 1.71 KHz -> should be 666Hz >> length of period: 585 us >> length of pulse: 100 us >>=20 >> # sysctl dev.am335x_pwm.1.period=3D1800000 >> # sysctl dev.am335x_pwm.1.dutyA=3D10000 >> result frequency: 3.24 KHz -> should be 555Hz >> length of period: 308 us >> length of pulse: 100 us >=20 > These two examples are overflowing the period variable. >=20 > I've the attached patch which enforces the maximum values where needed > (to avoid such overflows) and two new sysctls, one allows you to set > the prescaler for the PWM module and the other (which is probably more > interesting) allows you to check the actual PWM frequency. >=20 > The sysctl.am335x_pwm.X.freq can also be use to set an desired > frequency directly, it will try to get you the better setting it can > find for the desired frequency, which usually means get the bigger > period it can find to give the better PWM resolution that is possible > for a given frequency. >=20 > I've been able to drive R/C servos directly with this patch and the > following set: >=20 > sysctl.am335x_pwm.X.freq =3D 50 (digital servos may operate at higher = frequencies) >=20 > And then, for the cheap chinese servo i have here, i can get it to > travel almost 180o using duty values from 2000 to 6000 (YMMV). >=20 > I've checked the frequencies with a scope and they look fine for me. >=20 > Regards, > Luiz >