Skip to content

Instantly share code, notes, and snippets.

@AkiyukiOkayasu
Created July 17, 2020 07:33
Show Gist options
  • Save AkiyukiOkayasu/1edfaa4c191e3af7052296660131724d to your computer and use it in GitHub Desktop.
Save AkiyukiOkayasu/1edfaa4c191e3af7052296660131724d to your computer and use it in GitHub Desktop.
/*
i.MX RT1020のAudio PLLの最適設定を求めるコード
PLLFreq = ref * (div + ( num / denom ))
*/
package main
import (
"fmt"
"math"
)
/*
44.1kHz 22.5792MHz
div: 30
denom 625
num: 66
PLLFreq: 722.5344MHz(22.5792 * 32)
*/
/*
48kHz 24.576MHz
div: 32
denom: 125
num: 96
PLLFreq: 786.432MHz(24.576 * 32)
*/
func main() {
const ref = 24.0 // リファレンスクロック(MHz)
const dest = 24.576 // 目標の周波数(MHz)
var diff float64 = 100.0 // 目標の周波数との差
var PLLFreq float64 = 0.0 // PLLした周波数
for div := 27; div <= 54; div++ {
for denom := 0; denom <= 96000; denom++ {
for num := 0; num < denom; num++ {
PLLFreq = ref * (float64(div) + (float64(num) / float64(denom)))
if diff > math.Mod(PLLFreq, dest) {
diff = math.Mod(PLLFreq, dest)
fmt.Printf("div: %v, denom: %v, num: %v, PLLFreq: %v, diff: %v\n", div, denom, num, PLLFreq, diff)
}
}
}
}
fmt.Println("Finished")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment