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

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

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

    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:	1 
Size:	36.5 KB 
ID:	16593  

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,913
    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
    Junior Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    10
    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
    Junior Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    10
    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
    19,913
    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
    Junior Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    10
    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
    19,913
    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
    Junior Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    10
    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,380
    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
    Junior Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    10
    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
    Junior Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    10
    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
    Junior Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    10
    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,069
    What model is this for?

  14. #14
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,913
    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
    Junior Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    10
    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
    Junior Member
    Join Date
    May 2019
    Location
    Brisbane, QLD
    Posts
    10
    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.

Posting Permissions

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