Creating pulse 5us width

Status
Not open for further replies.

Wayne

Well-known member
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
 
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
 
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.
 
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:
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.
 
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..
 
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
 
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)

DS1Z_QuickPrint1.jpg
NOKEY

And here is the Teensy 3.2 image of NOKEY

DS1Z_QuickPrint1.jpg
NOKEY Teensy


Here are some other for comparison

DS1Z_QuickPrint4.jpg
Mem1

DS1Z_QuickPrint5.jpg
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
 
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..
 
Ok, I like to fix the program flow for this project. It is working good, but I think using if else statements is kind of a problem.

I use the if statement to digitalRead 1 of 16 inputs going low. I also in the statement added conditions to block out any other digitaReads from working.

example:
Code:
if (digitalRead(0) == LOW && B==0 && C==0 && D==0 && E==0 && F==0 && G==0 && H==0 && I==0 && J==0 && K==0 && LL==0 && M==0 && N==0 && O==0 && P==0)
  {
    A=1;
    loadunload();
    digitalWriteFast(SEC, HIGH);
  }

I have a total of 16 switches from 0-15 going to the teensy3.2.

I think I can use switch case along with typedef enum or somethink like it. As you can see on the single line its loadunload key. I have others like mem1, mem2, mem3 etc..
If no digitalRead, at the end of the statements is a

Code:
else if (digitalRead(15) == LOW && A==0 && B==0 && C==0 && D==0 && E==0 && F==0 && G==0 && H==0 && I==0 && J==0 && K==0 && LL==0 && M==0 && N==0 && O==0)
  {
    P=1;
    ImgChainFT();
    digitalWriteFast(SEC, HIGH);
  }  
  else {
    resetflags();
    nokey();
    
    digitalWriteFast(SEC, LOW);
    
  }

At the end of a loop is a delay(75); for repeat of this process in 75 ms intervals.

The voids will send out the code depending on which digitalRead ==LOW or if none, sends a nokey..
Example

Code:
void nokey()
{
  L = 9;
  digitalWriteFast(PIN, HIGH);
  delayMicroseconds(6);
  boolean seq20[10] = { 0, 1, 0, 1, 0, 1, 0, 1, 0};
  for (int i = 0; i < L; i++) {
    digitalWriteFast(PIN, seq20[i]);
    delayMicroseconds(OnTime);
  }
}

void loadunload()
{
  digitalWriteFast(PIN, HIGH);
  delayMicroseconds(3);
  L = 11;
  boolean seq0[11] = { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
  for (int i = 0; i < L; i++) {
    digitalWriteFast(PIN, seq0[i]);
    delayMicroseconds(OnTime);
  }
}

void tblsave()
{
  digitalWriteFast(PIN, HIGH);
  delayMicroseconds(3);
  L = 10;
  boolean seq1[10] = { 0, 1, 0, 1, 0, 1, 0, 1, 1, 0};
  for (int i = 0; i < L; i++) {
    digitalWriteFast(PIN, seq1[i]);
    delayMicroseconds(OnTime);
  }
}


You see a delayMicroseconds having a different value.. As the process in the loop and depending where we branch off, I had to adjust for timing of a pulse..
This pulse is a total time of 10us.
Here is that sample.. I needed a set of pulses for start and ID of the device.

Code:
digitalWriteFast(PIN, HIGH);
  delayMicroseconds(OnTime * 4);
  digitalWriteFast(PIN, LOW);
  delayMicroseconds(OnTime * 3);
  digitalWriteFast(PIN, HIGH);
  delayMicroseconds(OnTime);
  digitalWriteFast(PIN, LOW);
  delayMicroseconds(OnTime * 2);
  digitalWriteFast(PIN, HIGH);
  delayMicroseconds(OnTime);
  digitalWriteFast(PIN, LOW);
  delayMicroseconds(OnTime);
  digitalWriteFast(PIN, HIGH);
  delayMicroseconds(2);           // Timing issues.. reduced here and added difference in voids

That last 2 us will be added with the 1st write digital pin to a high.. Thus no change.
The 2 and the next when added works out to 10.. Maybe no by math, but time it includes the time of the program when it goes from point A to point B.

I need to time this out using my scope. It is working.. The upload is set to 96mhz fastest with LTO. Works ok even with prue code added.. But less than this, my code stretches beyond my timing.
3.2 or 3.5 teensy the same.

I was thinking of using the typedef enum..and along with switch case just not sure if it is the right choice and really how..
I think I be better off out of the if statements and better with case. And maybe with the use of the case I can drop the test making sure no other button press is added to the output.
1st button press owns the output. If you have press another button while the other is press, the 1st owns it, when you release the 1st the the other takes over.

BTW, this controls a table movement.
I wil need to add the WDT to this after.. We have made 150 boards.. Sorry Paul, had to buy all that stock from you.. The board builder was instructed (Name was Danny)

And thanks for your help..
Wayne

And this was my 1st 4 layer board.. And if you can answer, what schematic/board software do you guys use.. I have Diptrace and just bought Eagle/mo. plan..
 
And if you can answer, what schematic/board software do you guys use..

I use an ancient version of Pads for PCB layout, and nothing at all for schematics. I pretty much never use a schematic until the very end, and then I usually draw it in the Gimp so it looks good in a small size graphic.
 
"It works great".. This is from the company that wanted this handset. Thus I duplicated the signals correctly! I tell you, that's a lot of pressure off this old man.
With everyone's help, it amazes me what can be done. And just how great a program Paul has made with the Teensy.

The 1st project was 2 Teensy's 3.2 to handle serial signals, one for a different function. That then was reduced to a teensy 3.5 device. That then was able to add another product to 1 board. Logic switches added to change product.

Then this project. Manchester Coding.. Timing.. Buttons, lots of buttons.. And teensy 3.2 was the device.

These are on boards that have been design with Paul's boot chips. This last project was a 4 layer board (my 1st)..

Just wanted to give kudo's to all.. Bad thing with this they want me not to retire.. Want another 2 years.. I be 72 or 73.. At least its not sitting in front of a TV and getting fat right..

Thanks guys
 
Status
Not open for further replies.
Back
Top