Shop OBEX P1 Docs P2 Docs Learn Events
Alpine M-Bus interface — Parallax Forums

Alpine M-Bus interface

PFloyd36069PFloyd36069 Posts: 135
edited 2010-09-24 18:17 in Propeller 1
Hello all,

Im having a little bit trouble figuring out how to actually read the data coming from the radio. The signal is held high (around 10v) inside the radio. Then the signal grounds for certain amounts of time to transmit a 1(~.6ms) or a 0(~1.8ms). I hooked up a scope to my radio and i can definately see that signal. The part im having trouble with is how to program the prop to read it accurately. I tried modifying the sony ir decoder object (using the bs2 commands, mainly pulsin_us). i can get some readings that look right but there are a bunch of other ones that arent even close like ~.010ms or ~2.5ms. After i get this working, i hope to modify the circuit and code a bit so i can transmit data to the radio to simulate a cd changer.

here's a link to the page i got most of the info about the m-bus from: http://www.hohensohn.info/mbus/index.htm

Thanks,
Bryan

Comments

  • kwinnkwinn Posts: 8,697
    edited 2010-09-24 07:19
    Since a bit starts with a positive to negative transition the simplest method would be to measure the time between transitions. If the time between the first and second transition is less than the time between the second and third transition it is a "0", otherwise it is a "1".

    Relatively simple to do using CNT and WAITPEQ/WAITPNE.
  • PFloyd36069PFloyd36069 Posts: 135
    edited 2010-09-24 09:33
    So is spin fast enough or is this a good time to learn assembly :)
  • ericballericball Posts: 774
    edited 2010-09-24 11:23
    So is spin fast enough or is this a good time to learn assembly :)
    Since you're dealing with a timing sensitive signal, I'd recommend PASM.

    Hmm.. looking at the "spec" I'm not sure that WAITPNE/WAITPEQ is the best way to go. That gets you the first bit fine, but detecting the end of the packet becomes tricker as you can't break out of the WAITPNE.

    I'd recommend using a counter in !A mode, then set up some kind of polling logic which would check PHSA to see if it has changed and if the count is > 1.5ms (1 bit).
  • ericballericball Posts: 774
    edited 2010-09-24 11:43
    Fragment to read in the bits:
    		MOV		packet0, #0
    		MOV		packet1, #0
    wait4lo		WAITPNE		pinmask, pinmask
    wait4hi		WAITPEQ		pinmask, pinmask		' wait for low to high transition
    		MOV		bittime, CNT			' save CNT
    		CMP		us1500, PHSA		wc	' C = PHSA > 1.5ms
    		RCL		packet0, #1		wc	' 64 bit shift in bit
    		RCL		packet1, #1
    		SUB		bittime, PHSA			' calculate start of bit
    		ADD		bittime, us3000			' add 3ms
    		MOV		PHSA, #0			' reset bit counter
    		WAITCNT		bittime, #0			' wait for start of bit
    		MOV		bittime, PHSA			' read low counter
    		TJNZ		bittime, #wait4hi			' if non-zero, then get next bit
    
    Not shown is the CTRA setup or how to deal with the bits afterwards.
  • kwinnkwinn Posts: 8,697
    edited 2010-09-24 14:59
    Eric, you are probably correct about WAITPNE/WAITPEQ not being the best way to go when detecting the end of packet is considered even though it would work fine for the rest of the bits.
    At that slow a data rate it would be very easy to use a PASM counting loop to detect ones and zeros as well as the end of packet condition.
  • PFloyd36069PFloyd36069 Posts: 135
    edited 2010-09-24 18:17
    Wow thank you for the code :) I think im gonna try to learn some assembly because at the moment i know nothing about it, and dont know how to complete what you have provided. I have always wanted to learn it. it seems like more can be done with the prop by using it.
Sign In or Register to comment.