Please check my math, and SX timing questions
I am trying to sort out Khz to microseconds.
So here it goes for 50Khz.
50Khz is 50,000 pulses a second.
50,000 pulses a second is 50 per millisecond.
50 per millisecond is 0.05 per microsecond.
0.05 per microsecond is 1 pulse every 20 microseconds.
Every one agree so far?
If so, do you have a simple formula that will give me the 20us answer by plugging in 50Khz?
Next question. I'm a little confused about how Khz is measured.
Assume rising edge as active. Does 50Khz mean that the rising edge will go low then high 50,000 times a second.
In other words using the numbers above, would I see the rising edge pop once every 20us or is it twice.
Next question. Measuring the pulse.
I have tried the SX/B PulsIn which I believe has a resolution of 10us.
But the numbers did not make any sense to me. In a FOR loop the numbers would be 200 and under.
If I fired them off in a row with out the loop code I got 60 and under.
Which made me question my math, hence this post.
Anyway, my question is with the SX/B Interrupt.
I have read all the documentation, but can not wrap my head around accurately setting the Interrupt timing in SX/B.
Assume the SX28 with the internal 4Mhz crystal.
Could some one PLEASE post an SX/B example of a 20us Interrupt. And then a 40us.
I see the Clock/Timer example provided with SX/B but do not understand how they came up with a 1:128 perscaler to get a 5us interrupt.
I obviously do not understand that math either. [noparse]:)[/noparse]
My point is with the SX28 at an internal 4Mhz should easily be able to detect a 50Khz pulse. Yes, no?
Thanks
Jack
So here it goes for 50Khz.
50Khz is 50,000 pulses a second.
50,000 pulses a second is 50 per millisecond.
50 per millisecond is 0.05 per microsecond.
0.05 per microsecond is 1 pulse every 20 microseconds.
Every one agree so far?
If so, do you have a simple formula that will give me the 20us answer by plugging in 50Khz?
Next question. I'm a little confused about how Khz is measured.
Assume rising edge as active. Does 50Khz mean that the rising edge will go low then high 50,000 times a second.
In other words using the numbers above, would I see the rising edge pop once every 20us or is it twice.
Next question. Measuring the pulse.
I have tried the SX/B PulsIn which I believe has a resolution of 10us.
But the numbers did not make any sense to me. In a FOR loop the numbers would be 200 and under.
If I fired them off in a row with out the loop code I got 60 and under.
Which made me question my math, hence this post.
Anyway, my question is with the SX/B Interrupt.
I have read all the documentation, but can not wrap my head around accurately setting the Interrupt timing in SX/B.
Assume the SX28 with the internal 4Mhz crystal.
Could some one PLEASE post an SX/B example of a 20us Interrupt. And then a 40us.
I see the Clock/Timer example provided with SX/B but do not understand how they came up with a 1:128 perscaler to get a 5us interrupt.
I obviously do not understand that math either. [noparse]:)[/noparse]
My point is with the SX28 at an internal 4Mhz should easily be able to detect a 50Khz pulse. Yes, no?
Thanks
Jack
Comments
1 / 50,000 = 0.00002 (or 20 uS)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Just that easy!
Thanks Jon.
Jack
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Sorry, I meant to say so earlier.
It is at 50%.
Jack
it's just that simple...
Take any periodic waveform (sine, triangle, square, or whatever else), and measure the time difference between two equal transitions. For example, with a square wave, you might measure the time difference between two consecutive rising edges. This gives you the period of the signal.
The frequency simply tells you how many signal periods do occur within one second, i.e. it is the inverse of the period, IOW:
Frequency = 1 / Period
and (vice versa):
Period = 1 / Frequency.
Some practical values:
An SX chip clocked @ 50 MHz, or 50 * 10^6 Hertz will execute one instruction every 1/(50 * 10^6) second which is 20 * 10^-9, or 20 ns (Nanoseconds).
Clocked @ 4 MHz, or 4 * 10^6 Hertz, instruction cycles will be 1/(4 * 10^6) = 250 ns.
The "trick" with RTCC roll-over interrupts is that the interrupt service routine (ISR) should use the instructions
mov w, #-IntPeriod
retiw
on termination. With this, the interrupt service routine will be called every time when IntPeriod * InstructionCyclePeriod has elapsed.
To achieve a 20 µs interrupt as you have requested, you need to calculate the value for IntPeriod:
IntPeriod = 20 µs / 250 ns = 80.
IOW: Provided that the SX is clocked @ 4 MHz, use
mov w, #-80
retiw
to terminate the ISR.
If you are looking for a 40 µs interrupt, just double the value for the interrupt period, i.e. the instructions would read
mov w, #-160
retiw
Well, I know, my examples are in assembly - not SX/B. This is just because I personally "beat" the SX in assembly most of the time
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
Günther
Yes, Guenther, that was very helpful.
Thank you very much for that.
So, at 4Mhz and 250 ns, that is one instruction per 0.25 microseconds.
At 50Khz I would see the pin high for up to 80 instructions.
Man that is fast.
I'm just starting with Sx. It takes a little while to wrap your head around the speed.
So maybe I need a 10us interrupt to confirm a 50Khz signal.
Like so.
mov w, #-40
retiw
Jack