Skip to content

wrong return from machine_rp2_pwm.go Period #5139

@miroslavristic

Description

@miroslavristic

There is an error at the end of Period function causing wrong return from the function.

Last line of the function is:
return (16uint64(Int) + uint64(frac)) * uint64((top+1)(phc+1)1e9) / (16 * freq) // cycles = (TOP+1) * (CSRPHCorrect + 1) * (DIV_INT + DIV_FRAC/16)
The issue is caused by overflow in:
uint64((top+1)
(phc+1)*1e9)

The fix is simple, the line should be:
return (16uint64(Int) + uint64(frac)) * uint64((top+1)(phc+1)) * uint64(1e9) / (16 * freq) // cycles = (TOP+1) * (CSRPHCorrect + 1) * (DIV_INT + DIV_FRAC/16)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnext-releaseWill be part of next releaserp2RP2350/RP2040

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions