Is there something strange here?Code:TRISA = %11111111 ' Set PORTA to all input TRISC = %00000000 ' Sets all PortB pins to output ADCON1 = %10000101 ' Set PORTA analog and right justify result ADCON0=%00000000 low portc.4 low portc.5
Is there something strange here?Code:TRISA = %11111111 ' Set PORTA to all input TRISC = %00000000 ' Sets all PortB pins to output ADCON1 = %10000101 ' Set PORTA analog and right justify result ADCON0=%00000000 low portc.4 low portc.5
Last edited by pedja089; - 8th July 2016 at 22:42.
Easy! It’s giving you a wider pulse duration at the start to qualify the incoming data.
From there you only need to sample 32 times at the correct interval.
So look for that, then read it in with a 32 step loop.
Of course, better ways than reading into a 32 byte array, but quickest.Code:bitcode var byte[32] count var byte pulseduration var byte pulseduration = time from peak to peak for count = 0 to 31 bitcode[count] = inputpin pause pulseduration next count
You're omitting an important thing - MCU has own clock, wastes different time on program execution, but incoming data is sent async, so it can't wait for MCU to become ready, so my guess, how it all should work, is as follows:
As pulse arrives, we start recording it as fast as possible, after pulse sequence finished, we just count numbers of 1's and 0's recorded, and based on that, decide what to do with decoded data. Considering total sequence duration and speed, I guess, external sram or eeprom might be needed?
That depends. You didn’t display the duration.
If it’s several uS duration pulses, the falling edge of the first longer pulse is the place to mark time,
then waste half a pulse duration before the for-next loop. If you can roughly synchronise from the first pulse (which is what it’s for),
it takes time for the two clocks to drift apart.
If you were to sample bits as fast as you can, you’d still want to do that from the falling edge of the first pulse.
Does your hardware have the LCD that is in your code?
That should get the 32 bits straight into a four byte array.
Code:' main: @ clrwdt ' if portc.4 = 1 then ‘ count initial pulse duration leadcnt = leadcnt + 1 else leadcnt = 0 endif ' ' if leadcnt > expectedduration then' qualify initial pulse duration burst: ' sync to initial pulse falling edge if portc.4 = 1 then @ clrwdt goto burst endif ' for rotcnta = 0 to 3 ' shift data into 32 bit buffer databuffer = 0 for rotcntb = 0 to 7 ‘ shift data to each byte databuffer.bit0 = portc.4 databuffer = databuffer << 1 dataarray[rotcnta] = databuffer pauseus peaktopeakduration next rotcntb next rotcnta ‘ leadcnt = 0 endif ' goto main ‘
Last edited by Art; - 9th July 2016 at 16:34.
surely a candidate for timer1 and gate control
Warning I'm not a teacher
Bookmarks