Skip to content

Commit

Permalink
Update lower VCO frequency limit according to datasheet update
Browse files Browse the repository at this point in the history
Fixes #682
  • Loading branch information
ithinuel committed Sep 4, 2023
1 parent 6756d35 commit 20d9fac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
6 changes: 6 additions & 0 deletions rp2040-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## Fixed

- Fixed minimum PLL's VCO frequency according to updated datasheet - @ithinuel

## [0.9.0]

### MSRV
Expand Down
21 changes: 11 additions & 10 deletions rp2040-hal/src/pll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ pub mod common_configs {

/// Default, nominal configuration for PLL_USB.
pub const PLL_USB_48MHZ: PLLConfig = PLLConfig {
vco_freq: HertzU32::MHz(480),
vco_freq: HertzU32::MHz(960),
refdiv: 1,
post_div1: 5,
post_div2: 2,
post_div2: 4,
};
}

Expand All @@ -141,18 +141,22 @@ impl<D: PhaseLockedLoopDevice> PhaseLockedLoop<Disabled, D> {
xosc_frequency: HertzU32,
config: PLLConfig,
) -> Result<PhaseLockedLoop<Disabled, D>, Error> {
const VCO_FREQ_RANGE: RangeInclusive<HertzU32> = HertzU32::MHz(400)..=HertzU32::MHz(1_600);
const VCO_FREQ_RANGE: RangeInclusive<HertzU32> = HertzU32::MHz(750)..=HertzU32::MHz(1_600);
const POSTDIV_RANGE: Range<u8> = 1..7;
const FBDIV_RANGE: Range<u16> = 16..320;

let vco_freq = config.vco_freq;
let PLLConfig {
vco_freq,
refdiv,
post_div1,
post_div2,
} = config;

if !VCO_FREQ_RANGE.contains(&vco_freq) {
return Err(Error::VcoFreqOutOfRange);
}

if !POSTDIV_RANGE.contains(&config.post_div1) || !POSTDIV_RANGE.contains(&config.post_div2)
{
if !POSTDIV_RANGE.contains(&post_div1) || !POSTDIV_RANGE.contains(&post_div2) {
return Err(Error::PostDivOutOfRage);
}

Expand All @@ -161,7 +165,7 @@ impl<D: PhaseLockedLoopDevice> PhaseLockedLoop<Disabled, D> {

let ref_freq_hz: HertzU32 = xosc_frequency
.to_Hz()
.checked_div(u32::from(config.refdiv))
.checked_div(u32::from(refdiv))
.ok_or(Error::BadArgument)?
.Hz();

Expand All @@ -180,9 +184,6 @@ impl<D: PhaseLockedLoopDevice> PhaseLockedLoop<Disabled, D> {
return Err(Error::FeedbackDivOutOfRange);
}

let refdiv = config.refdiv;
let post_div1 = config.post_div1;
let post_div2 = config.post_div2;
let frequency: HertzU32 = ((ref_freq_hz / u32::from(refdiv)) * u32::from(fbdiv))
/ (u32::from(post_div1) * u32::from(post_div2));

Expand Down

0 comments on commit 20d9fac

Please sign in to comment.