This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Bit Banging 1MHz signal with RM48L952ZWT

Other Parts Discussed in Thread: RM48L952

I have a synchronous clock-data pair of RS-422 signals that transmits an SDLC frame of 13 words plus header and CRC... The data is sampled at a rate of 400Hz and transmitted on the falling edge of an externally generated 1.0152 MHz data clock. I am supposed to sample data on the rising edge of the data clock. Between data frames, no data are transmitted which causes me to read all "1"'s or the SDLC "idle" data command. The opening and closing flags have a unique flag byte pattern of a zero (0), six ones (1) and a zero (0). The contents of the rest of the data frame are constrained to five contiguous ones (1) by zero insertion before transmitting. These zero bits are to be removed by me. There is not a slave select coming from the device to indicate "real" data.The data-stream is considered to be a sequence of bits with no arbitrary division into bytes. So, there is no mechanism in place to ascertain when to start shifting data into a receive register and zero insertion is used causing detection of closing flag to be near impossible. What I have done is implement a polling loop and bit bang the data stream. I only have (1) one (us) of time between each clock transition. I believe I am losing data since I do not have enough cycles to detect rising edge of clock, determine value of data, let alone determine if I need to remove inserted zero... Am I right?

void syncDataSteam()

{

while ( ((linPORT->DIN >> PIN_LIN_RX) & 1U) == 1U); // while "idle" data... all "1" bits... wait for "0" bit

while ( ((mibspiPORT1->DIN >> PIN_CS3) & 1U) == 0U); // If clock bit is low... wait for raising edge of clock

g_ln200_buff[0] |= (linPORT->DIN >> PIN_LIN_RX) & 1U; // set bit high/low

g_ln200_buff[0] = g_ln200_buff[0] << 1; // Rotate bits

while ( ((mibspiPORT1->DIN >> PIN_CS3) & 1U) == 0U); // If clock bit is high... sample data on rising edge of clock

g_ln200_buff[0] |= (linPORT->DIN >> PIN_LIN_RX) & 1U; // set bit high/low

g_ln200_buff[0] = g_ln200_buff[0] << 1; // Rotate bits

while ( ((mibspiPORT1->DIN >> PIN_CS3) & 1U) == 0U); // If clock bit is high... sample data on rising edge of clock

g_ln200_buff[0] |= (linPORT->DIN >> PIN_LIN_RX) & 1U; // set bit high/low

g_ln200_buff[0] = g_ln200_buff[0] << 1; // Rotate bits

while ( ((mibspiPORT1->DIN >> PIN_CS3) & 1U) == 0U); // If clock bit is high... sample data on rising edge of clock

g_ln200_buff[0] |= (linPORT->DIN >> PIN_LIN_RX) & 1U; // set bit high/low

g_ln200_buff[0] = g_ln200_buff[0] << 1; // Rotate bits

while ( ((mibspiPORT1->DIN >> PIN_CS3) & 1U) == 0U); // If clock bit is high... sample data on rising edge of clock

g_ln200_buff[0] |= (linPORT->DIN >> PIN_LIN_RX) & 1U; // set bit high/low

g_ln200_buff[0] = g_ln200_buff[0] << 1; // Rotate bits

while ( ((mibspiPORT1->DIN >> PIN_CS3) & 1U) == 0U); // If clock bit is high... sample data on rising edge of clock

g_ln200_buff[0] |= (linPORT->DIN >> PIN_LIN_RX) & 1U; // set bit high/low

g_ln200_buff[0] = g_ln200_buff[0] << 1; // Rotate bits

while ( ((mibspiPORT1->DIN >> PIN_CS3) & 1U) == 0U); // If clock bit is high... sample data on rising edge of clock

g_ln200_buff[0] |= (linPORT->DIN >> PIN_LIN_RX) & 1U; // set bit high/low

g_ln200_buff[0] = g_ln200_buff[0] << 1; // Rotate bits

 

Is this proper way to bit bang... Or do you have other ideas... Thanks!

  • William,
    I would suggest programming the N2HET to do this task, it has a SHFT instruction that can be used and it will be capable of dealing with a 1MHZ external clock without loading the CPU at all. There is a 'UART' example e2e.ti.com/.../324165
    to give you an idea of what you might be able to do.
  • Anthony,
    So to be certain... I will need to ask the hardware engineer to blue wire the device clock and device data to N2HET pins... correct?
  • William,
    MIBSPI1NCS[3] should be shared with N2HET1[21] according to the datasheet I have for the RM48L952, ball J3.
    So you would need only to blue wire the LIN pin to an N2HET1 pin, assuming that N2HET1 is free.
    To check out whether you can implement the SDLC function in the N2HET though, you can use the HET IDE without making HW changes.
    If you have a waveform file you can feed it to the HET IDE and test your program against it.
    If you don't have a waveform file but have a physical system that you can capture from with a scope or logic analyzer, then you can use the Synapticad Waveformer Pro tool to turn this into stimulus for the HET simulator. The tool you would need to purchase but there is a 90 day eval offered w. the HET IDE so you can make sure it does what you want before committing to purchase.
  • Anthony,
    Thanks, I would like to verify that I in fact can implement the SDLC function in the N2HET and then "verify answer" just incase I need to ask for clarification. This is good stuff though... William
  • Sure - let us know if you get stuck on anything.
  • :) I'm stuck....

    When attempting to download 'UART' example, I get the following:

    Access Denied

    You do not have permission to view/download this item.
  • By the way, what exactly does your SDLC frame look like? Is it 'almost' SPI but has bit stuffing that you need to account for?
  • Anthony,

    I got the two links mentioned above just fine. Thank you. Actually it is "almost" SPI like, in fact the hardware engineer originally intended for me to use SPI Slave mode in MSP430 pin 9.4 which on MSP430 is both UART and optionally SPI SIMO... Why do you ask?
  • Hi William,
    1) Well if it's exactly SPI then I would be steering you in the wrong direction with NHET because the device has multiple MibSPI ports.
    2) if it's synchronous like SPI but has bit stuffing then I think HET's the way to go. but your program will probably be different significantly than the UART example. I'd look at the UART example as just a proof of concept for how you can implement a serial port.
    If you send me the details I might be able to sketch you up a quick outline of a HET program to get started with.
    It takes a while to learn the HET instruction set although if you have something to start with then it's not bad at all.
    Best Regards,anthony
  • Hi William,

    This is completely untested - but it's what I would start from if I were building this.   It does assemble correctly, so you should

    be able to load the project into the HET IDE and start feeding stimulus to test it out.

    I put a few comments in but it may take some studying to figure out what's going on.  

    I think this could execute in under 16 cyles actually which means you could set the clock divider register to 0x400.

    That would also increase the sampling rate of the clock and data pins to about 6.8MHz which is a decent oversampling of the 1MHz input clock.


    Since you're new to HET I should probably say this. 

    The HET will take a snapshot of the pin state at the start of each loop resolution period.
    All the "BR" that test pins operate on the snapshot.   So even though they are sequentially executed in the HET program, the data they test was captured in an instant.   It's a little different this way than your CPU bit bang code. 

    Meaning that testing the data pin for high or low in the HET code after testing that a rising edge on clk was detected, is actually not testing the data pin value at a later 'time' than the clock pin value.   both were captured at the same instant and that instant is tested by all the instructions that execute during the same loop resolution period. 

    -Anthony4503.sdlc_sketch.zip

  • Anthony,

    The engineer has blue wired the LIN pin to N2HET1[6] pin and I am studying the sdlc_sketch code. This will probably take several days in "William" time to hash out... Will get back with you then. Thank you ahead of time. When this works, it will be the first implementation of its kind that provides LN200 IMU data on an Ethernet backbone instead of having to use an FPGA core and other special equipment. At least for us it is "bleeding edge". William
  • Hi William,

    That's awesome.   Exactly the type of feedback we love to hear.

    Thought about this a bit more last night.  I think there's a few issues in the 'sketch' that you'll run into.

    1) You'll probably need 2 shift registers not just INSHFT.   The way the code is written, if 111110 are the last
         6 bits in INSHFT then if a 0 is the next bit captured, it's determined to be stuffed. INSHFT isn't modified.
        The problem would be that any number of 0's after 111110 would be dropped.

        Instead I think you always need to shift into INSHFT so that 0 + 111110 becomes 0111110 in which case
     if the next bit is a 0, it won't match the 'stuff' pattern.

        But then the 2nd shift register would shift in all data bits - except for the stuff.

    2) there's no protection against shifting in data bits before the 1st 'flag'.  

        You could add a DJZ with initial value of 0 to bypass the bit count and byte output whenever the value is 0.   This would be the 1st instruction in the bit processing.    

        Then when the flag is detected, write a value to the DJZ that is the max length of bits that you want to be able to receive between flags.  

        This way the first bits don't come out until after the first flag.   And if the flag occurs but then an infinite number of non-flag bits come in,  at some point it'll hit the max length, the DJZ will be 0 and it'll stop capturing till a new flag comes in.

    Best Regards,

    Anthony

  • Hi William,

    This is embarassing - there were some syntax errors in the file I uploaded last night but they weren't listed during the assembly process due to the location inside a macro; instead assembly just stopped.

    So I fixed that and also made a few tweeks per the previous mail.   Added the 2nd shift reg and the guarding of the byte output based on a max # of bits after each flag.  It defaults to 0 so no bytes should emit until the 1st flag is detected and then this sets the count to 4096 bits.. which will decrement till the next flag resets to 4096 bits.  If it decrements all the way to 0 then the byte output will stop.

    I just picked 4096 off the top of my head - guessing your max bit count is shorter but anyway it's a '.equ' statement change to MAX_BITS and you can make it whatever you want.

    Also I forgot to mention that whichever HET pin you tied bluewired the LIN RX to - you can change the headers on top of the HET file to match your board:

    PINDAT .equ 21

    PINCLK .equ 22

    Sets pin 21 as data and pin 22 as clock.  If you load the program into N2HET1, this will mean N2HET1[22] and N2HET1[23].  

    If you aren't using pin 22 but using another HET pin for CLK just change the equate...

    -Anthony

    5047.sdlc_sketch2.zip

  • Anthony,

    Thanks for double checking example. Hopefully soon I will be able to catch issues such as you caught. Thanks for tweaking per previous email and the information on modifying the program to fit my environment. Hopefully, sometime tomorrow I be able to start giving more meaningful feedback of results... William
  • Anthony, been a while since I have replied. I was pulled to other higher priority projects. I am now back on this project. I have obtained the WaveFormer Pro 14 day license to be able to load the project into the HET IDE and start feeding stimulus to test it out... I am failing miserably doing so. I have done the input stimuli tutorial provided with HET IDE successfully however when I use hetm.drive_6.in and hetm.drive_21.in as data and clock (INPUTS) respectively, it does not seem to be reading that properly. I assumed that hetm.drive_#.in were the NHET pins 0-31. Is it possible for you to point me in the right direction or to refer me to a post that will help me from a TI HET IDE perspective to generate stimulus for het code generated. I do not figure that SynaptiCAD will be able to help since they are not TI. Thanks. Hardy
  • Hi WIlliam,

    Please check your versions if you don't mind.   We released a HET IDE 03.05.00 that fixed some crashes but there was an issue with the synapticad version that came with it and it was not possible to provide stimulus.  We fixed that too.  

    Current versions that are in the HET IDE installer are HET IDE 03.05.01 and Syncad 20.06.

    Although Syncad can be updated separately so you may have a later version if you made an update.


    Also did you work through the updated tutorial or the older one that was included in the HET IDE installation?
    In the last version we reworked the tutorial too - as I had gone through the one that was included in the HET IDE and it was not working / names had changed.   The newest version of the tutorial is only available online now: 

    It is possible to give stimulus to the HET simulator - and I think I captured the recipe in the updated tutorial.  But it's tricky too so easy to make a mistake. 

    If you are still stuck,  and you want to send me your HET IDE project folder zipped - I'd be happy to look at it.

    Best Regards,
    Anthony

  • I should add one thing - I think this may be still the case.

    There are 3 ways to provide stimulus:
    1) through a VCD file (via Waveviewer Free.. under the hood)
    2) through a BTIM file that was created with Waveformer Pro
    3) manually entering the transitions in the HET IDE stimulus tab.

    Note that the program name for 1) and 2) is different. From what I recall for some reason you can't use the VCD file method if you are using the 'Pro' license.
    What you can do is import the VCD, save as a .btim file, and then use the .btim file method if you have pro.

    The BTIM file I believe can feed the HET IDE from either the free or the pro version but you have to have the Pro version to create the BTIM file. (-or- have to have a BTIM file that someone created for you already..)
  • Anthony, I installed the correct versions. I also went through the new tutorials. Note that the tutorial does not start from the IDE, I had to go to C:\ProgramData\Texas Instruments\Hercules\HET IDE\03.05.01\resources\help\HET IDE Tutorials (www.ti.com) to open .pdf...
  • Anthony, I have spent 2 full days working this... I am clueless why I cannot get my own generated stimuli to work. I copied both waveforms from a Tektronix MSO2024B in .csv files. I then imported both using WaveFormer Pro and then saved them as .btim files. I then open my project, assemble and load, merge both .btim files (clk and data), change their names to hetm.drive_6.in and hetm.drive_21.in and no joy...
    The only thing that seems to make my program start to take expected branches (not correct) is by using method 3:
    --->3) manually entering the transitions in the HET IDE stimulus tab. If I use HET IDE Stimulus Creator adding Pin 6 and Pin 21 then I get some expected reactions, I know that I am getting stimuli, but I do not know where, why, how. I assumed that it comes in on hetm.drive_6.in and hetm.drive_21.in but they are not even shown on the WaveFormer Pro GUI so maybe I have made a bad assumption. I simply cannot get method two to work for me. ---> 2) through a BTIM file that was created with Waveformer Pro... Is there something I have missed? Is there an application note that you know of? Thanks, Hardy
  • Hi William (or Hardy? sorry not sure...),

    If you want to send me your project directory zipped up I'll look at it.  It's probably something simple like a box that isn't checked or a naming issue, but hard to tell exactly without seeing it first hand.

    I'm using MATLAB to generate .vcd files myself and this works well with the HET IDE, so I'm pretty sure we can make what you are trying to do work too.


    Best Regards,
    Anthony

  • Hey Anthony,
    Hardy is my middle name so Hardy is fine... :) Turns out I used the method described in Tutorial 8 - Input Stimuli From WaveFormer Pro and started getting results from program. So I then made hetm.drive_6 and hetm.drive_21 visible and started changing their waveforms and I seem to be able to use that to trouble shoot the HET code. I still do not know why the files from Tektronix do not work so I will zip this up and send it to you. I have been in meetings all day so it will probably be tomorrow... Thanks, Hardy
  • Ok thanks Hardy.

    It may be something like changing the signal type from 'watch' to 'drive' in the GUI of Waveformer Pro...
    But that'll be easy to see when you send me the files.

    Best Regards,
    Anthony
  • Hi Hardy,

    Just want to follow up - I don't think you'd sent me the files in question but want to make sure I didn't miss them.

    Thanks and Best Regards,
    Anthony