Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 3 1 2 3 LastLast
Results 1 to 25 of 58

Thread: Reading a 1Mhz -15V to Gnd clock

  1. #1
    Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    50

    Reading a 1Mhz -15V to Gnd clock

    Hi,

    I'm very new to teensy but thought it could help me with a midi retrofit project.

    I chose the Teensy++ 2.0 due to the 5V tolerance & the number of digital I/O's. I'm working with a Keyboard/Organ that I'm hoping to interface the teensy into by means of reading its (the keyboard's) clock signal. *This is so i can spit out logic signals back to the keyboard.

    The clock signal is 1Mhz, that swings from -15V (Low) to 0V (High), the High & Low cycles each 0.5us. *see attachment

    I figure i will just need to do a simple resistor voltage divider to get that -15V (low) down to -5V, but will I also then have to invert the voltage to +5v with an opamp, or can the Teensy++ 2.0 handle negative voltages on it's I/O pins?

    Just so I know I'm not barking up the wrong tree, this board should be able to track/follow a 1mhz external clock?

    Thank you
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	clock.jpg 
Views:	7 
Size:	36.5 KB 
ID:	16593  

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,299
    Quote Originally Posted by martianredskies View Post
    or can the Teensy++ 2.0 handle negative voltages on it's I/O pins?
    No. The pins only work with 0 to 5V signals. Driving the pin below GND can damage the hardware.


    Just so I know I'm not barking up the wrong tree, this board should be able to track/follow a 1mhz external clock?
    The CPU on Teensy++ 2.0 runs at 16 MHz. So if you're going to try to actually do something every 1 microsecond, unless "track/follow" is extremely simple, the CPU probably won't be fast enough. You'd probably do much better to use one of the much faster Teensy 3.x boards. Teensy 3.5 is 5V tolerant and has a similar number of pins, and runs much faster so you'd have a much better chance of doing something useful within 1 us.

    You mentioned only a clock. If there's also a data signal, you could use something like the SPI port in slave mode. Then you'd get a byte every 8 us, with the data from 8 clock cycles. That's still pretty fast, but probably more feasible than running code for each clock cycle.

    If there isn't any data, only this clock, and "track/follow" means something like measuring the frequency, maybe the FreqCount library could help.

  3. #3
    Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    50
    Hey Paul,

    Thanks for the reply, shouldnít be too hard i guess to get it into 5V logic.

    Regarding the timing, the 1uSec master clock i believe is divided down inside the cmos chips after studying related service manuals closer, i think the note timing is more like every 3uSec (per note), and its sent as a 4-bit parallel data code.

    Iíve got a 20mhz scope on the way so iíll be able to tell in more detail.

    But the way i believe it acts is that for 14-note polyphony, a sync signal is sent out every 42uSec, and within that period, every 3uSec a 4-bit parallel code is sent for each of the 14 voice/note channels that corresponds to note and octave data.

    Given those conditions, should the teensy++ be able to handle the task Vs every 1uSec?

    Thanks

  4. #4
    Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    50
    Actually i got that wrong, i think it does need to send out a 4-bit parallel code every 1us. Its just does so using 3 nibbles over a 3uSec period (touch data -> octave data -> note data (c# to c).

    Maybe iíll have to create an array to speeed things up.

    That being said, no one plays keyboard at that rate, its more for communication timing when a note is detected.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,299
    That's a very unusual and very fast interface for a musical instrument.

    If it really is sending 4 bits (so 5 signals, CLK and D0 to D3...) every microsecond, you're probably going to need a much faster board. Probably best to plan on using Teensy 3.6. Of course, design your circuitry to convert to 3.3V signals, since Teensy 3.6 is not 5V tolerant.

  6. #6
    Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    50
    I think the engineers at Yamaha were overachievers

    Iím wondering though, if i setup a 8-bit array already prefilled with the code corresponding to the key (c# to c) and octave data, shouldnít a 16mhz board be fast enough? How many cycles does it take to read an array value and apply, say, a bitwise AND operation to write those values to four digital i/oís?

    Read 8-bit array value -> bitwise AND x4 every 1 uSec.

    Sorry if this is a braindead question, Iím just trying to understand how certain things apply to clock cycles. Like the teensy++ 2.0 can handle 16 instructions every 1uSec, are bitwise operations performed in 1 cycle? How long does it take to read a const array value?

    Thanks, ive never coded using dev boards, only computers that are +200x faster so iím in new territory

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,299
    Quote Originally Posted by martianredskies View Post
    shouldn’t a 16mhz board be fast enough?
    No, probably not fast enough.


    How many cycles does it take to read an array value and apply, say, a bitwise AND operation to write those values to four digital i/o’s?
    The only way to really know the answer is to compile the code, then look at the assembly listing, and check how many cycles each instruction really takes.

    In Arduino, click File > Preferences to turn on verbose output while compiling. Then look at the messages after compiling to figure out the temporary directory where Arduino compiled your code. Look in that location for the .LST file.

    Near the end of the datasheet is a list of all AVR instructions and how many cycles each takes.


    Thanks, ive never coded using dev boards, only computers that are +200x faster so i’m in new territory
    I can tell you from many years of experience, doing this with a 16 MHz 8 bit AVR chip will be extremely difficult. I'm not saying "impossible", though it might be, depending on many small details. My general advice, first and foremost is to really confirm the actual requirements. But if it is truly is as you've said, I would advise using a much faster microcontroller.

    If you like want to follow that advice, that's your choice. But don't expect I or anyone else here can guide you step-by-step on the low-level to achieve this highly improbably speed on such an old and slow microcontroller. I can point you to features like the LST file and AVR instruction documentation. The rest is up to you.

  8. #8
    Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    50
    Is the only difference between 3.5 & 3.6 the 5v tolerant pins on the former?

    Its a little cheaper here in Australia, and its easy math going from -15v to 5v electronically.

  9. #9
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,453
    No, the 3.6 has a maximum clock rate of 180MHz while the 3.5 has 120MHz. The 3.6 has 1024kB of program flash, the T3.5 only 512kB.

  10. #10
    Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    50
    Thanks. Iíve gone ahead and ordered a 3.6 board. Appreciate your patience with my questions.

    I think even if it was possible, having room to expand is wise. Not only that but now i can likely do two channels and control each sound chip seperatley over two midi channels.
    Last edited by martianredskies; 05-13-2019 at 07:50 AM.

  11. #11
    Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    50
    One last question or two;

    Iíve built inverting opamp channels with gain reduction to turn the (-15v to 0v) logic into (3.3v to 0v).

    When looking at the scope, it looks good but it seems to go a ďhairĒ into negative voltage territory when initially going LOW (around -250mv). Can the 3.6 board handle absolutley no negative voltage?

    If so i imagine iíd use a 1n914 in series to block negative voltages, but thatíll come with a 0.7v voltage drop (less with schotky). What is the minimum voltage for the teensy digital inputs to read HIGH?

    Thanks

    *realise i could change the gain to compensate for the forward voltage drop, but ive already soldered all the resistors into a cramped project board, donít want to have to remove resistors to change gain if possible.

  12. #12
    Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    50
    ah, poor opamp circuit design on my part, needed to add a small 680ohm output resistor (in addition to input & feedback resistor). The opamp was oscillating, causing spikes into negative range, 220ohm improved it, slighly larger eliminated it going into negative.

  13. #13
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,138
    What model is this for?

  14. #14
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,299
    Quote Originally Posted by martianredskies View Post
    Can the 3.6 board handle absolutley no negative voltage
    It can handle up to -300 mV.

    Any farther than -0.3V risks damage. That includes behavior during startup and shutdown, so it's wise to check what your opamp actually does when power comes up and shuts down. Some opamps are notorious for briefly driving a full scale positive or negative output before the feedback loop takes control.

    If you're using more than 1 signal, even if the opamp has enough bandwidth, you might also verify how well the propagation delay matches between signals. 1 MHz is a pretty fast signal. If you use a very fast opamp, like 100 MHz gain-bandwidth product, that's still only an open loop gain of 40 dB at 1 MHz. If you more than 1, how well they match each other's performance might matter, might affect whether you receive other signals with their timing relationship to the clock properly translated to 3V logic.
    Last edited by PaulStoffregen; 05-17-2019 at 12:39 PM.

  15. #15
    Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    50
    Thanks Paul, i will look into all these points you highlight, definetley some things I hadnít considered.

    Iím attempting to do 12 channels using 3 quad opamps using tl074ís (best available without ordering), they are 13v/us. One thing i noticed is my inverting gain formula doesnít match expected results, where i was expecting +3.3v, iím get more like 2.3v. Perhaps this relates to a tl074 being underpowered for the application? Iíll have to see what is available in dip-14 that is faster to test.

    Iíll include a 3.3V zener to gnd at the input pins to the teensy, thatíll protect overvoltage, Iím going to see what results i get just tying the negative rail of the opamps to gnd, perhaps that will elimate the need to diodes for blocking negative voltages.

    Thanks again

  16. #16
    Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    50
    Iíve figured it out. I simply need an RC lowpass filter on the oupuf of the opamps going to the teensy pins. That gets rid of negative spikes. I guess a -3db filter around 1mhz should suffice.

    The gain issue was another flub, i had the wrong resistor in 1 of the feedback paths. I now get almost within .03v of a full 3.3v logic signal.

    Iíve got some 3.3v zeners enroute, iím thinking the rc filter + zener to gnd at the input pins should have me covered protection wise.

    Should almost be ready to start coding

    *on another note the tl074ís from ST, which i have, seem to be rated higher than the TI parts, around 16v/us. They seems fast enough to handle a 1mhz signal reduction, maybe when iím amplifying for +3.3v to -15v for the output signal there may be issues with timing.

  17. #17
    Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    50
    Iíve been breadboarding some 3.3v zener diodes after the RC filter ive created (on the opamp outputs), since the gain on the opamps brought the signal to around 0v-3.28v (ish), i didnít expect a 3.3v zener to cause any voltage drop, but it reduces the voltage about 0.5v.

    Iím using 220ohm resistor + 680pf cap for the rc filter, my peak voltage dropped from 3.28v to around 2.75v.

    Iím guessing the zener is creating some sort of voltage divider action, and maybe 2.75v is high enough for the teensy 3.6 to register HIGH. Is this something i should just live with, accept a 2.75v voltage for HIGH logic?

  18. #18
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    193
    Quote Originally Posted by martianredskies View Post
    maybe 2.75v is high enough for the teensy 3.6 to register HIGH. Is this something i should just live with, accept a 2.75v voltage for HIGH logic?
    According to the NXP datasheet for the K66, at p.7:
    https://www.nxp.com/docs/en/data-she...4M180SF5V2.pdf

    it should, because HIGH is at 0.7xVdd and Vdd is 3.3V (so Vhigh = 2.3V). That said, it would be better to have a larger margin, IMHO (but can't help you about that... maybe a different Zener model with lower forward R?)

  19. #19
    Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    50
    Iíd just read its almost common practice to add 3.3v zeners on the inputs for protecting pins, anode to ground. If i add the zener before the rc filter, no voltage drop but i see negative voltage spikes, almost like its negating the rc filter function.

  20. #20
    Member
    Join Date
    Sep 2014
    Location
    South Dundas, Ontario, Canada
    Posts
    37
    I wonder if a 6N137 optcoupler would work as your level shifter. It may work at 3.6V for Vcc, although the datasheet says 4.5V minimum. It would provide ground loop protection for your keyboard.

  21. #21
    Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    50
    Maybe a phototransistor based optocoupler? Such as;

    https://docs-apac.rs-online.com/webd...6b812cf975.pdf

    No power supply pin, just whatever is present at the collector.

    Not sure how transistors handle negative voltages at the collector though, so while it seems fine for going to teensy input pins not sure how it would work for outputs (driving a -15v signal).

    Something to think about

  22. #22
    Member
    Join Date
    Sep 2014
    Location
    South Dundas, Ontario, Canada
    Posts
    37
    That opto is too slow. I was thinking of a 6N137M. You may need to fiddle with the resistor values to get the desired rise/fall times. Also, it is uncertain as to how much delay this circuit produces to make this not work for you.

    Click image for larger version. 

Name:	6N137 interface.jpg 
Views:	7 
Size:	12.7 KB 
ID:	16674
    Edit: This circuit will invert your input signal. Will it matter?
    Last edited by KOC62; 05-22-2019 at 01:44 PM.

  23. #23
    Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    50
    Inverting shouldnít be a problem, just a change of logic in the teensy code.

    This part looks similiar but is designed to work at 3.3v;

    http://www.mouser.com/ds/2/149/FODM8061-95625.pdf

    Just another quick question, iíve scanned the datasheet for the microcontroller in the 3.6 board. I can see a max current per pin of 25ma, but no minimum listed. I see youíve chosen a 330ohm resistor in your example which equals 10ma. Has anyone tested the lower limits? Iím just wondering what kind of wiggle room i have.

    Thanks again for the schematic and tips.

  24. #24
    Member
    Join Date
    Sep 2014
    Location
    South Dundas, Ontario, Canada
    Posts
    37
    I didn't do any testing, but drew the diagram to provide a proof of concept. Your selection of a high speed opto is better since it is designed to work with 3.3V.
    The 330 ohm was an arbitrary value I picked. The datasheet you just gave uses 350 ohms for the pull-up resistor of the opto's output (e.g. Fig 11). The input to the micro will not draw much current due to the high input resistance. It's the output pin that you are probably referring to for a max of 25ma.

    What wiggle room are you looking for?

  25. #25
    Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    50
    Iím wondering if iíve made it overly complicated. The original circuit uses a 4050BP non-inverting hex buffer, wired in an oddish way; its supply voltage is connected to gnd and the Vss is tied to -15v.

    This has 6 buffers onboard;

    https://pdf1.alldatasheet.com/datash.../datasheet.pdf

    It (the 4050) is driven by a cmos output between -15v to 0v, though.

    In my experience things arenít usually easy, but i wonder if i wired up another 4050 with Supply voltage to gnd and Vss tied to 3.3v if that would be all that is necessary (driven from the same -15v to 0v cmos output). I just donít know how they will behave with different polarities).

    These opamps ive build seem overly complicated with rc filters and voltage protection, and they behave poorly with the inputs floating (annoying while prototyping).

Posting Permissions

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