Comments (7)
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.
Thanks Tom, that's great news!
from codebug_tether.
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.
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.
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.
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.
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)
- USB Device not recognised HOT 5
- AssertionError HOT 4
- Issues with set_pullup() HOT 1
- Digital outputs 0 and 1 not working on v0.8.0
- SerialException: Could not open port /dev/ttyS0 [Errno 13] Permission denied: '/dev/ttyS0' HOT 3
- installation.rst for Linux omission
- How do I wire my Codebug to my Raspberry Pi? HOT 2
- macOS issue -- ImportError: No module named 'serial'
- AssertionError#2
- Raspbian Jessie gets a kernel panic when Codebug is connected HOT 4
- Set leg output state HOT 2
- Finding Win7 driver HOT 1
- Control of CodeBug LEG state not working as expected HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codebug_tether.