Frequency of a function generator #1319
Replies: 2 comments
-
Posted at 2019-05-09 by @allObjects
is not quite enough to know what to do. From the code I assume you have to measure the frequency - do you? Depending on the hardware you use - clock of the processor - you get more or less done... So your interrupt routine has to be as short as possible (1). The interrupt routine is setup with the setWatch and gets triggered by the rising edge of the signal coming from the function generator... Your debounce is a bit odd for multiple reasons... (2) Having challenges with resources requires usually to take a more elaborate way to go after the problem than the obvious one... (3) Also to go for precision, you try to read multiple times or over a time span and do some math to get to the detail... (4) I do not want to do your home work - and familiarity with a language is not the problem here (5) - so I try to support you in exploring options... I numbered the hot spots with (1)...(5), where some variation / action is needed. You are correct in the way that JS is for certain things too slow for the blunt or brute force approach, because it is interpretative and with Espruino even interpreted from source code (and not from 'compiled' byte code as for example in the browser); therefore the advice is correct and you follow the instructions found at the linked page. For your information: an free running, empty loop gets you to a few kHz. But with how Espruino handles hardware interrupts (6) you may - for a first stab at the problem (with limited, but may be even sufficient precision) - get away without going that deep 'into the woods'. Regarding (5): you define Regarding (6): to give you some hints here in relation with your code: @gfwilliams, the creator of Espruino is fully aware of the timing challenges an interpreted language has in handling of hardware interrupts. So what he did is building two layers: a low level, fast implementation of catching the interrupt, do the minimum of work like collecting the times an stick the information as an event object into an event queue. When the processor then finds time to handle the events in the queue in the slower java script layer as 'connected' to pin and directed with function by the Due diligence will get you there! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-05-13 by @gfwilliams Hi, The exact same question was already asked at http://forum.espruino.com/conversations/333178 a fortnight ago :) To be totally honest you don't need to be familiar with JS - you just need to go to http://www.espruino.com/STM32+Peripherals#resetting-registers and copy the big section of code out and paste it in. It'll then count pulses on pin |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2019-05-09 by Mijunior
I need a program that reads the output of a function generator, between 10 and 20kHz, I already know that javascript is a bit slow making it difficult to acquire the data, I already tried to use setWatch:
however I am not having satisfactory values. I was advised to use the STM32F4 hardware (http://www.espruino.com/STM32+Peripherals), but I do not know a way to do this because I'm new to the language.
Beta Was this translation helpful? Give feedback.
All reactions