Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 11 of 11

Thread: Creating pulse 5us width

  1. #1
    Senior Member
    Join Date
    Oct 2014
    Posts
    162

    Creating pulse 5us width

    well all, this is more likely my last project for work before I retire. (unless they want me to work from home which will be somewhere in Arizona and out of cold Utah.)
    I'm thinking of using the Teensy 3.2(3.1 I have to play with) and or using the teensy 3.5 which we have in our current products and has worked since 2015 (3.2 2015 to 2017. 3.5 current) and still going strong.

    The issue at hand is a wired remote that sends Manchester Code to the system. I'm not willing to bother much on using a library for the Manchester code, but it does have a preface to tell the system that it is a handset.
    I have scoped the output and see the common signal that is sent and to the data (button function) is a total of 185 us. The signal repeats at 75 ms intervals.

    20 possible codes are from 10011111 (no key) to 10000000 the 1st button action. Thus 20 different conditions (4 are spares)

    Since the 1st 20 are binary, I'm thinking of using case then send the code somehow (still thinking on a way of doing) XOR or shift.

    Usually when I type stuff out I start thinking I can do that, but can I..... (Brain Pause)

    So I can maybe do the preamble 1st and then trail the key code and repeat 75 ms later.

    Well actually about the retirement.. Work has put me into a semi retirement... But moving to Arizona in the very near future.. faster if they don't put me back into full time.. So I'm here Mon/Tues.

    So ideas will help.
    In the meantime I will do some timing stuff on my teensy 3.1 or 3.2.. And maybe try the 3.5 I have.. Scope in hand..

    Thanks a head of time..

    Wayne

  2. #2
    Senior Member
    Join Date
    Oct 2014
    Posts
    162
    So I tried both my Teensy 3.1 and the 3.5 and found the 3.5 can produce a accurate 5 us square wave.

    I'm will now look into using SPI. I think I might be able to create 10000110 code or like to send. I looked at it yesterday, if I can make it 5 us wide.

    wish there was something like sendcode(11100011, width, interval) or something like that.. Off to play somemore.

    Wayne

  3. #3
    What was the shortest accurate interval on the 3.1?

  4. #4
    Senior Member
    Join Date
    Oct 2014
    Posts
    162
    Using Micros, and setting up for 5 off/5 on, I could never get to 5 us. It was like 6.9 us and would change width every so often. I set speed to 120 overclock and faster with pure code and LTO. The 3.5 handled it great.
    I'm playing with ShiftOut now but moving to SPI. Seeing if I can just output a signal thats like 20 or so bits wide. Thats what I need I think for the start and button code.

  5. #5
    Senior Member
    Join Date
    Oct 2014
    Posts
    162
    I have so far created the actual code. Still hard coded. Need to figure out how to do it with not using delayMicroseconds option. Elapsetimer I think I need to use.

    Scratch the above..
    I was looking over Delay and Timings Functions and saw noInterrupts(); mentioned. So I know I'm not using interrupts at all, and I added the statement in my loop.
    The jitters has disappeared. Timing is at 5.2 us, but I will try some options on speed and flashing.
    Last edited by Wayne; 01-17-2019 at 04:03 PM.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,940
    Maybe some of the jitter reduction ideas here can help?

    https://forum.pjrc.com/threads/27690...ll=1#post64142

  7. #7
    Senior Member
    Join Date
    Oct 2014
    Posts
    162
    Thanks Paul,

    Looking into now.. Accuracy a bit off on what I'm doing, like 5 us is 5.2 us.. I was called back into work today for something else and I can stay and play.

  8. #8
    Senior Member
    Join Date
    Oct 2014
    Posts
    162
    So I decided to try a SAMD21 type board using the same routine.. Wow what a difference.. It did not work as well, in fact it was pretty bad.. I could not get the pulse to 5 us at all. The waveform did a bit of breathing.. Kind of a wave at a game.
    I even tried all sorts of times and elapsemillis.. no avail. So if this goes through, be doing some actual testing on a table system..

  9. #9
    Senior Member
    Join Date
    Oct 2014
    Posts
    162
    Well, I just compared the original to the teensy emulated device waveforms.
    I have 17 conditions in a IF and ese if's after 1st if statement. The action call voids to complete the waveform.
    So I have a start waveform and if no action of a button, defaults to a void nokey.
    If you press a button, it will act in the if statement and go to some other void (start waveforms and then void (related to a button action)
    What I found out, as the program grew, the start waveform last bit changed in timing.. Slightly in microsecs, but it did.. Actually got longer.

    For some reason, at the beginning of the voids is the nokey one. This is called last in the if statements. I change that last pulse timing at the end of the start to a minimal time is micros (2us) HIGH
    In the nokey I had to add a new high out of 6 us. to correct the timing of the start of the 1st bit (pulse of the code).

    So the alteration is that I partially construct the HIGH pulse at the end of the Start pulse routine and fix the rest at the beginning of the other routine.

    So the nokey which is the last of the loop is at the top of the voids.

    Now the strange part. As I go down the voids, the construction of that one high pulse in timing kind of reduce in timing..
    I started off with adding a 3 us pulse at the top of the voids and near the bottom it goes down to 1 us.

    The top voids are the earlier buttons on the teensy position on the board. Like 0, 1, 2, etc 3 on up to 15 (13 is skipped to 16 due to led on 13.). (12, 16, 14 instead of 12, 13, 14)

    This is the 3.1/3.2 teensy which I will use in this system. The 3.5/3.6 is a slight overkill.

    All this over 1 pulse that was too fat (should of been 5 us but was like 7 us or 8 us) and it changed on the selection of button.

    I'm glad I caught it..
    The program runs with nointerrupt.

    Wayne

  10. #10
    Senior Member
    Join Date
    Oct 2014
    Posts
    162
    I'm back.. Now since this is working.. I need to make a test fixture. (Machines cost $$$)..
    This is a Manchester code..

    So here is the original scope image of a NOKEY condition (no buttons pressed)

    Click image for larger version. 

Name:	DS1Z_QuickPrint1.jpg 
Views:	3 
Size:	87.7 KB 
ID:	16626
    NOKEY

    And here is the Teensy 3.2 image of NOKEY

    Click image for larger version. 

Name:	DS1Z_QuickPrint1.jpg 
Views:	3 
Size:	77.2 KB 
ID:	16627
    NOKEY Teensy


    Here are some other for comparison

    Click image for larger version. 

Name:	DS1Z_QuickPrint4.jpg 
Views:	4 
Size:	77.1 KB 
ID:	16628
    Mem1

    Click image for larger version. 

Name:	DS1Z_QuickPrint5.jpg 
Views:	4 
Size:	77.3 KB 
ID:	16629
    Mem2

    So I need to detect pulse length both in positive and negative. Since timing of each represents the condition of a key press.

    I do have a + and - signal to use from the output of the handset. These are from the Teensy 3.2 output and the Original output of the IC in the handset (INVERTED)

    I was thinking of attached interrupt along with pulsein(). I have tried the pulsein and it will skip the 1st pulse (6 +'s instead of 7 +'s).
    I also trigger it via a 75 ms test.. The signal occur every 75 ms. I have no idea if pulse in can do a HIGH and LOW test one after another.
    That's where I think attach could work.. Toying with it now.. Not much to post yet of code.

    Wayne

  11. #11
    Senior Member
    Join Date
    Oct 2014
    Posts
    162
    Live and Learn.. You can if you do not place a pulseIn(xxxx,HIGH) right after pulseIn(xxxx,LOW)
    Also, I know the code repeats at 75ms. So when I get a value over 74000 I should start my reads. I however loose the 1st pulse I think..

    I had to stop and program a old Simblee chip to find out during an update of one of my devices, it place a new arm-none-eabi-gcc folder in the arduino15 folder in tools. I had to delete the new and let the older one work.. I have a backup.

    Since the items are working, I can now continue.

    I will update what I have done.. But basically I have pulse that are 5us as one condition. I will take the + and - pulses and determine the binary code. A 5us HIGH is a 1 while a 5us LOW is a 0.
    So if value1[1] is 5us, its 1 and if value2[1] is 10 us its 2 0's Like 1 0 0. This represents the Manchester code. I do not know if the Arduino Manchester decoder would even work for this.. The original code xxxEDCBA or for
    nokey 10011111 but in Manchester it looks like this 1,0, 1, 0, 1, 0, 1, 0, 1, 0...EDCBA I guess..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •