Tutorial example output anomaly using low level access PPI on MDBT42Q breakout board #3305
Replies: 12 comments
-
Posted at 2020-03-05 by @gfwilliams
Yes, 32kHz
The MDBT42 module has a crystal in it. Just a high speed (8MHz?) one though, no low speed (32kHz) one - that is just an on-chip RC oscillator calibrated by the high speed one.
It should, yes. However it appears not to be working for some reason. Calling
Yes. Clock runs at 32kHz, you're checking every 5 seconds. It's basically 32768*5 |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-06 by Robin Thr 2020.03.05 Thank you @gfwilliams for taking the time to respond promptly.
From your detailed explanation, I believe I now have enough to push on. I have a bunch of time this weekend to dive into the examples, and with a few other trial attempts, may be able to get to the bottom of that example.
On the drive into work this morning, had the exact thought, (before your post #2 arrived) but hadn't the time last evening to test. In any event, I should have the ammo to get the task I am after, done.
Geez, do I feel like a Dolt! I even had that detail (in words) nicely spelled out beneath question #4! Amazing how I was so immersed in, and convinced that, the issue was with how the crystals (or lack of) controlled the timing at an underlying level, causing me to ponder why 163 822 wasn't smaller than 32 000, but not stepping back and looking from the 10,000ft level to view the interval duration and the run time effect with time. Thanks for the insight and now afford you the time back to Bangleland. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-06 by @gfwilliams Great - if you find out why the example isn't working I'd love to be able to get the docs changed. As a starting point you could attempt to do it by using a rising edge on a second pin to stop the RTC (since we know that rising edge on BTN1 works to start it). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-08 by Robin Sun 2020.03.08 Ran into another snag. While I'm getting the hang of wiring (via code) the PPI tasks and events, un-wiring them has me a bit stumped. While flags stop and clear seem to work, when using say Not a super critical solve now issue, as powering off, does allow the nRF52 to reset, it would make for a good tutorial, should I be able to determine the proper un-wiring sequence. I presume it is in the reverse order of setup, so I'll continue to play until frustration sets in. ;-) Back to the datsheet as I'm not sure if the issue is with the event and state or the interconnect, or a combination.
Quick patch fix for 'Button held down example' is to reverse the 'btnu' and 'btnd' var definitions, but I'm not convinced just yet that, . . . that is all there is to it, as, . . . . post #6 |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-08 by Robin Sun 2020.03.08 Six hours later and another peculiarity. Adding a Entering Am attempting to simulate an IRQ using the following instructions: Heading: Interrupts Setup:
Execution: After around a two second wait, a near 100Hz square wave appears on pin D20/D22 The setWatch function never executes. Entering cw() or Some Helper functions and comments removed for brevity
Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-09 by @gfwilliams I think the issue may be that while the PPI is disabled, the pin number is still set in the GPIOTE, which might stop the rest of the hardware from being able to access it. You could try:
and see if that helps. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-11 by Robin Tue 2020.03.10
Well, I have given it the good ol' college try, but am now out of ideas, and faced with a new anomaly. I thought I saw the same possible 'Stepped On' pin issue, from your explanation in post #7, and changed that to a separate adjacent pin, but the setWatch never triggers with that change either. I noticed the following over the weekend, but dismissed it, that is until this evening. I powered down the setup, and shut off the PC. Tonight, I powered up the setup and the PC. New anomaly. For a sanity check, I uploaded the code file I submitted in post #6 but this time, the output square wave was crunched to 1Vp-p. Odd, as this all worked when I posted. I made several attempts with other code I had, and the output now swings to the rails, 0-3v3. I chose to retest, and now have a repeatable scenario. The first upload seems to always crunch the output, and the second upload seems to always allow full range of output swing. No ideas, but the PPI setup isn't allowing the pin output. I'll continue to try settings pin modes and playing with the start interval etc. A more perplexing issue is what I stated in post #6. I didn't want to start a new related thread so as not to draw attention. Entering cw() or clearWatch() will also inadvertently kill the PPI setup.
Reviewing ' If no parameter is supplied, all watches will be removed' I tried with both a no argument and also passing the setWatch ID in cwi() but both exhibit the same output killing result on Pin D22. As clearWatch is meant to do just that, then why is PPI getting clobbered? No idea here either. I'll continue to test, and this weekend, I'll try these examples with STM32 to see if more satisfactory resulsts can be obtained. -------------------------------------------- **Attachments:** |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-11 by @gfwilliams I'm afraid I'm a bit too busy getting things shipped to help out much with this for the next 2 weeks. If the output is getting cropped to ~1V peak to peak then chances are you're trying to write to a pin that is already set to an output though Also internally setWatch uses GPIOTE in order to work, so if you're setWatching on the same pin then that could be a problem. You could also try changing the |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-15 by Robin Sun 2020.03.15
The truly bizarre! Things that changed: Last week, I powered off the circuit and scope, Google Chrome locked up Windows, so I had to warm reboot. Yesterday I powered on the scope and applied power to the circuit and played with an external setWatch file for a sanity check. I loaded the file from post #6 and to my amazement it ran this time as expected. Floored!! Was it the newly introduced setWatch as it was indicated in post #9 that setWatch uses gpiote? Was it that last week after using ppi.disable that when re-uploading code PPI doesn't get set correctly? So I tinkered with the code a bit, both from the console and the editor side, ending up hosing something. So I uploaded the original file again, but this time no luck, even after re-applying power to the circuit. So, possibly a timing thing setting up PPI, perhaps? Steps: Uploaded code which starts the PPI rtc. Played with rtc.prescaler and re-uploaded. Even with WebIDE Setting 'Reset before Send' set, the new prescaler value doesn't take effect. That said, a hard poke32(rtc.tStop,1) stop of the counter, then re-uploading does work. That sort of makes sense as we are only to poke a value, and the counter doesn't need to peek at it a second time as it is already doing it's work. But, in the process of re-uploading code, the counter is restarted, so it is reset(1) that may be the culprit.
So, should a reset(1) also control the stopping and resetting of what ever PPI peripherals (intuitive as reset means reset - implying all parts of chip) are running, or is this a procedural thing where the user must follow a strict path in reverse order of setup, before they upload code, meaning reset(1) only applies to Espruino in RAM?
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-15 by Robin Sun 2020.03.15 Eight hours later . . . . Before I started messing with the channel within enable, Found this note: ** Real time counter You should only set on ch2 as 0 and 1 are used by Espruino/Bluetooth This function intentionally doesn't set state itself to allow you to still query RTC0/1 without modifying them. > http://www.espruino.com/modules/NRF52LL.js So did a complete code re-write, carefully inserting working snippets and using channel 3 for the enable and thought I was making progress. Now I've found a repeatable/reproduceable condition using the PPI counter. The prescaler calculation needs a review. Any value greater than 2047 (0x07FF) yielding a frequency slower than 16Hz or 62.5msec always outputs a 5Hz or 200msec output wave.
While this will need to be corrected, at the moment I still don't have a means to reflash the MDBT42Q, although I expect to pick up a tablet once a suitable one can be sourced. At least a week out as of today. Firing up the STM32 WiFi to compare techniques . . . . > https://www.espruino.com/STM32+Peripherals |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-17 by Robin Tue 2020.03.17 Spent yesterday toying with Low Level Access on STM32 using a Pico. All went well, but not all the functionality appears to be available as with the nRF52LL So, this morning, after heeding this note:
I modifed the toggle channel to 4 and the enable channel to 3. Now the setWatch can be added without killing the underlying PPI counter. But, the setWatch never detects a pulse that clearly swings both rails. That is, until during code cleanup to post to the forum, I failed to remove a commented out line of code within the setInterval initialization that caused a separate function to execute unintentionally. There is also another anomaly, that when specifying 'af_output' using pinMode, that after PPI signal is sent to the external LED, that the mode changes from 'af_output' to just 'output' with no intentional change by me. (maybe this is why this code block now appears to be stable? - but don't we need the special 'af_' prefix as we are using PPI?) While I continue to play/learn how all the bits work under the hood, the following still needs review:
When playing with this code file, be aware it takes around five seconds to upload and initialize before commands may be entered.Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-21 by Robin Fri 2020.03.20 Found this note: 'Note: On nRF52 chips (used in Puck.js, Pixl.js, MDBT42Q) setWatch disables the GPIO output on that pin. In order to be able to write to the pin again you need to disable the watch with clearWatch.' This explains why setWatch was killing the PPI task, as PPI was writing to that pin, a positive pulse output. Also adds a bit of insight to the post #9 statement:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-03-05 by Robin
Wed 2020.03.04
This is a first attempt at attempting to grasp the concepts behind PPI using nRF52. I am at a point where peppering the NRF52LL.js module with console.log() statements is/will be the next step in revealing the PPI mysteries.
PPI - the "Programmable Peripheral Interconnect". This allows you to 'wire' peripherals together internally.
nRF52 Low Level Interface Library
Example code heading: 'Use the RTC to measure how long a button has been held down for'
Scenario: Onboard button is held down (at L10) for approx one second. Output shows the counter (L11) value. A clear command is issued, but the counter continues to output what appears to be an overflow (L12-L14) value, despite the button never being pressed a subsequent time.
I added a few console.log() statements to the example code block, that show the counter increments around twelve times for each console.log() statement that is executed, even after the counter is cleared.
Q1: What is the counter frequency? (presumeably 32Khz)
Q2: Clarification needed:
The datasheet indicates two external crystals, but the schematic shows none. I presume a software generated clock, 32Mhz?/64Mhz? but unsure what the frequency actually is, that is used to determine the clocking here. Several references to 32Khz, but that is 1000 times slower than xtal.
Spec
p.550 shows two 32Mhz xtals
p.103 19.2 LFCLK clock controller
32Mhz
L10 comment: // no prescaler, 32 kHz
From module: cc3stop : true, // if cc[0] matches, stop the timer
Q:3 L14 indicates on an up that rtc.tStop should occur. After the clear, shouldn't the clock stop and therefore no additional counting?
163822
Q4: What is this value? (total counter edges?)
From the L10 comment above 32K is 32 000 but 163 822 is five times that value
I'm choosing not to upgrade to 2v04 just yet, as PPI example existed prior to 2V03
Will continue to read/filter through spec.
Modified example to reveal counter changes and ci() function to halt output
Reference Links
NRF52LL Module source
nRf52 spec
MDBT42Q breakout board schematic
Beta Was this translation helpful? Give feedback.
All reactions