Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Latency on pin interrupts on WebMite
Author | Message | ||||
OomNiel Newbie Joined: 06/11/2024 Location: South AfricaPosts: 3 |
Good day all, I was wondering if someone here can cast some light on the expected latency for pin interrupts using the Setpin function (e.g. Setpin GP2, intl, buttonIntHandler, pullup) in WebMite. When running a simple program like: option colourcode on OPTION EXPLICIT OPTION DEFAULT NONE option autorun on Setpin GP2, intl, buttonIntHandler, pullup setpin GP3, dout pin(GP3) = 0 'for testing int latency 'Main Loop do Timer = 0 Do while Timer < 2000:loop pin(GP3) = 0 loop 'Interrupt handler for GP2 going low sub buttonIntHandler pin(GP3) = 1 'for testing latency end sub I get latency of between 57 to 87 micro-Seconds as shown in this image: The blue trace is a simple button press and the yellow trace is the interrupt service routine toggling a pin high. When a more substantial program is running, like pulling data from an MQTT broker the latency increases to about 10 mS and it can vary greatly (as much as 300 mS). So my questions are: 1) What is the priority of pin interrupts using WebMite? 2) Why is the latency varying greatly depending on the complexity of the code? 3) Is there another route to follow in order to get constant uS latency on pin interrupts? (Using the PIO state machines perhaps?) 4) Are these varying latencies due to the nature of interpreted languages? I have searched the forum but could not really find a conclusive answer. Greetings, Niel. |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6772 |
From the Webmite manual version 5.08.00 The exception is when SETPIN is used to set up COUNT pins. These use a hardware interrupt so override the above. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
Due to the nature of the BASIC language and being an interpreter, interrupts are only checked when a command has completed (the one exception is the PAUSE command). Most commands complete quickly but some can take a long time (for example, the TEMP() function). MMBasic was never intended for demanding applications that require fast and repeatable interrupts. For that the only way to go is to write your program in a compiler such as C/C++. 1) What is the priority of pin interrupts using WebMite? These are listed in the manual (page 44). 2) Why is the latency varying greatly depending on the complexity of the code? It all depends on how long a command will take to complete, especially on the WebMite with its Internet capability, that can be very variable. 3) Is there another route to follow in order to get constant uS latency on pin interrupts? (Using the PIO state machines perhaps?) Not really, you are asking the BASIC interpreter to halt interpreting a command and start interpreting another set of commands. That has all sorts of complications including an enormous stack to hold the full context of the command being executed at the time of the interrupt. This applies to both PIO routines and embedded C routines. 4) Are these varying latencies due to the nature of interpreted languages? In a nutshell, yes. Geoff Geoff Graham - http://geoffg.net |
||||
OomNiel Newbie Joined: 06/11/2024 Location: South AfricaPosts: 3 |
Thank you for sharing your expertise regarding this issue...much appreciated. Regards, Niel. |
||||
Print this page |