Capturing data from MSF time receiver

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
unus
Posts: 1
Joined: Mon Dec 01, 2014 12:17 pm

Capturing data from MSF time receiver

Post by unus » Mon Dec 01, 2014 12:31 pm

Hi

I'm trying to read the data from a time receiver module (http://www.pvelectronics.co.uk/index.ph ... ducts_id=2) and I'm totally lost. I do a fair bit of VB.NET programming so I'm not a total programming newbie but I'm not getting far with this and wondered if someone had a code snippet for reading the pulse from a pin.

I've actually got it reading something but have no idea what it is and it doesn't seem to relate to what I'm expecting . I'm trying to use the TimerChannel class to get this but I'm lost when it comes to what to use for freq, prescaler and period and how to get the program to keep reading the pulses short of just sticking it in a perpetual loop (I'm thinking a timer interrupt but I can't quite understand how that works or when to invoke it).

Thanks for reading

David

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Capturing data from MSF time receiver

Post by dhylands » Tue Dec 02, 2014 8:02 am

Looking at http://www.joejaworski.com/wwvb/ it would appear that you can receive one bbit per second.

We need to measure pulse widths of 200, 500, and 800 msecs.

I put together an example over here for measure servo pulses using a Hardware timer: http://wiki.micropython.org/platforms/b ... r-Examples Scroll down to the Input Capture section.

Let's suppose that we're using Timer 2, which has a source_freq of 84 MHz (i.e. Timer(2).source_freq() == 84000000)

If we picked a prescaler of 83, then we would get a timer clock frequency of 1 MHz. Ideally, we'd like to choose a prescaler of 839,999, however the prescaler is limited to 16 bits, so if we pick a prescaler of 8399 then we'll get a timer clock frequency of 10 kHz, or 100 micoseconds per timer clock.

Since we want to measure on the order of a second, we need a counter which can count up to 10,000. Since all of the timers are at least 16 bit, we can use a period of 0xffff which will yield counter values between 0 and 65535 (0xffff)

Using the example on the Wiki, you should now be able to measure pulse widths using Input Capture. I'd recommend that you use a little state machine in your interrupt handler to detect sync and then record 0 and 1 bits into 4 15-bit values (or maybe 2 x 30 bit values). It turns out micropython can store 31 bits into an integer without having to allocate memory. Then once you've collected all 60 bits, you trigger your main task to decode the values.

Post Reply