Coder Social home page Coder Social logo

Comments (7)

tompreston avatar tompreston commented on July 29, 2024

Thanks for raising this. I know what the issue is and the fix will be pushed in the next update (coming very soon!).

from codebug_tether.

jam3sward avatar jam3sward commented on July 29, 2024

Thanks Tom, that's great news!

from codebug_tether.

jam3sward avatar jam3sward commented on July 29, 2024

Thanks for looking at this, it hadn't occurred to me that the clock frequency was 12MHz rather than 4MHz.
I can confirm that the output frequency now matches the parameter passed to pwm_freq(), although the available frequency range has been reduced as a result. For example, 1kHz is no longer possible because (750000 / 1000 - 1) = 749 which is too large for the 8-bit value expected by pwm_on(). However, higher frequencies such as 3kHz work correctly. It looks like the minimum frequency is now about 2920Hz with the current implementation.
Assuming this is a PIC, it looks like the minimum possible frequency with the hardware at 12MHz clock would be 732.42Hz with PR2=0xFF, T2CON=0x07, CCPR1L=0x7F and CCP1CON=0x3C. I might have a play with the Python code to try this.

from codebug_tether.

tompreston avatar tompreston commented on July 29, 2024

I think you're assuming a 10-bit resolution for the timer since this is how the duty cycle is calculated. However period is calculated using just the 8-bit PR2 value.

(48,000,000 Fosc / 4) / 16 pre-scaler = 750,000 timer 'ticks' per second. If PR2 is set at a maximum of 0xFF then that's 750k / (0xFF + 1) = 2929.6875 Hz

See section 15.3.4 in the device manual.
http://ww1.microchip.com/downloads/en/DeviceDoc/30684A.pdf

I hope that helps!

from codebug_tether.

jam3sward avatar jam3sward commented on July 29, 2024

I was assuming Fosc = 12MHz and plugging into the equation under 15-1 in section 15.3.3 of the PIC manual, but it looks like Fosc = 48MHz? That would explain the factor of 4 difference! The blockly version at codebug.org.uk does allow frequencies below 1kHz, so I guess a different clock frequency may be configured there?

To explain the context to all this, I was trying to get lower frequency notes out of the CodeBug.

from codebug_tether.

tompreston avatar tompreston commented on July 29, 2024

USB requires 48MHz - if we didn't have it this fast then you wouldn't be able to talk to CodeBug at all! Programs from the website run slower in order to reduce power (16MHz).

from codebug_tether.

jam3sward avatar jam3sward commented on July 29, 2024

OK that makes perfect sense, thank you. It was actually the web-site version I was originally looking at, and where I was hoping to get lower frequency notes, and that's what led me to look at codebug_tether. Now I can appreciate that isn't possible (at least without further reducing the clock, or doing it in software). Thanks for responding anyway.

from codebug_tether.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.