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

Thread: Help using Teensy 3.5 to modernize industrial controller

  1. #1
    Junior Member
    Join Date
    May 2019
    Posts
    8

    Help using Teensy 3.5 to modernize industrial controller

    Hello,

    I would like to use a Teensy 3.5 as smart peripheral in an old Z80 based industrial controller. The industrial controller is a wire wrapped board with extra room that would easily accommodate an Teensy 3.5 as a 40 pin DIP 5V device.

    I can write the Z80 assembler side of the interface but don't know what interface options I have on the Teensy side.

    Are their any examples that I can read up on within this forum or on other forums?

    I have access to the Z80 address and data bus so I can use either I/O or memory based interface.

    Since the Teensy is so powerful I wondered if I could support command and data buffers and how deep they could be.

    I would really like to communicate to the industrial controller via the Teensy's USB interface and be able to load jobs and check job progress that way.

    Since the Z80 is slow (4Mhz) and the Teensy is fast would I be able to leverage Arduino libraries and be able to get the functionality using Sketches?


    Any thoughts and suggestions would be appreciated.

    Thank you.

  2. #2
    Junior Member
    Join Date
    May 2019
    Posts
    8
    Hi this is Neon2,

    Let me restart. I'm new to the Teensy product and environment. I have purchased a Teensy 3.5 and I've written some simple Sketch based programs. I would like to do more but I don't know how to uncover how to use the peripherals in Sketch based programming. Is there a document that lists the peripherals and available libraries ?

    I would like to start with building an 8bit bidirectional Command/Data interface using digital pins. Are there examples that you can point me to that use such and interface.

    Thank you.

  3. #3
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,051
    Welcome - scanned your original post and found it intriguing - wasn't sure of a good answer.

    I went and looked - it seemed somebody did a tape device interface - found the thread this time - but I don't see a source code link : https://forum.pjrc.com/threads/55633...?highlight=z80

    It seems that won't have any common bus protocol to run - Serial UART, i2c, SPI - but seems you have the pins to do data transfers?

    Off hand I don't think of an example for that - but is certainly possible. Go to the pjrc.com page and find the schematic for the T_3.5 and find the 'port' with the needed number of parallel pins for the data - they will be distributed around the Teensy where pin ordering is controlled by common functionality with Prior Arduino/Teensy definition.

    With a fresh T_3.5 finding and ordering 8 to set as IN or OUT and then Read and Write as a block will be easiest. The pick the other Control pins for Direction and Ready or whatever is needed. The control pins will be Fixed IN or OUT I suppose and they would be read with digitalReadFast or write with digitalWriteFast for best performance.

    Not sure if that is enough to get you started?

  4. #4
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    193
    Quote Originally Posted by Neon2 View Post
    I can write the Z80 assembler side of the interface but don't know what interface options I have on the Teensy side.
    Let's start with this part of your question, since it's the easiest (for me at least)
    Here you may find the peripherals at your disposal:
    https://www.pjrc.com/teensy/techspecs.html

    And here you can find the pin function tables (3.5 is second from top):
    https://www.pjrc.com/teensy/pinout.html

    As you see, there are a lot of interfaces you can choose from.
    Everything is usable from Arduino sketches after having installed the Arduino IDE (I suggest 1.8.9) and *then* the Teensyduino software, which enables Teensy programming from Arduino IDE. You can find the latest version here:
    https://www.pjrc.com/teensy/teensyduino.html

    You use the interfaces (UART, SPI, I2C etc.) just as you would with Arduino (same syntax etc.).
    In some cases, there may be special libraries with enhanced/high performance support for Teensy-specific hardware, but for now, I would leave them out...

    And then, of course, there's always "bit-banging": as Defragster suggests, you may identify the pins belonging to a specific 8-bit port (which may not be contiguous!) and read/write them with appropriate 1-cycle instructions, to get the best speed.

  5. #5
    Junior Member
    Join Date
    May 2019
    Posts
    8
    Thank you Defragster and XFer for the assistance.

    If I were choosing a Microprocessor for a design I would read the Hardware and Software design manuals and have a good idea on what I could do with the device.

    For Teensy 3.5 and Arduino Sketch development where can I find the Arduino command/instruction set and the function use documentation?

    Defragster, you pointed out finding the pins, ordering to 8 and then R/W as a Block. One of my questions was can I combine digital pins into 8 or 16b I/O, you gave me a yes. How do I find more about that and that level of detail for all the other pins/peripherals ?

    Can you tell me if there is any FiFo like capabilities that I can harness for command queuing?

    Thanks again.

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,051
    Meant to link to Arduino ref on web - here it is for pinMode I mentioned - all else links from there:: arduino.cc/reference/en/language/functions/digital-io/pinmode/

    The MCU manuals are linked here : https://www.pjrc.com/teensy/datasheets.html

    If you are dong raw I/O - not through a hardware supported bus - then there won't be a FIFO - it will be up to you do define and control commands.

    At least one port has 8 pins - but IIRC non present 16 from a single port. Here is link :: pjrc.com/teensy/schematic.html

    There is a good post with pin mapping in a table format in the Forum … somewhere - but in time the schematic makes sense - physical MCU pin abbrev to external pin #. And MichaelM has a good spreadsheet posted around.

    I saw a post go by today with a 6502 interface - it probably has port I/O code that is LowLevel ( outside Arduino for this ARM versus AVR's in standard Arduinos ) - but the digitalRead/Write is on the Arduino ref page to start - and the Fast() version is a more direct Teensy method - for Compile time Constant pin values.

  7. #7
    Junior Member
    Join Date
    May 2019
    Posts
    8
    Defragster,

    Ah that's what I was looking for :-)

    Question on pinmode(). I don't see a "block" capability associated with pinmode. When I search for Block it appears to be a comment group. I thought it may have been a way of combining the 8 digital pins into a group such that all get read or written at the same time.

    Wow the K64 datasheet is 1800 pages...

    Thanks again for the assistance.

  8. #8
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,051
    That is covered by this :

    port I/O code that is LowLevel ( outside Arduino for this ARM versus AVR's in standard Arduinos ) - but the digitalRead/Write is on the Arduino ref page to start - and the Fast() version is a more direct Teensy method
    That is TBD - certainly doable - just not in a quick post and not a first task.

    Start with setting pinMode as IN and OUT and organize the overhead for the Control Signals that will be single pins controlled with digitalRead/Write. And on those PORT reserved pins - pick ONE and get the Z80 synchronized and test that one BIT between the two using the digitalRead/Write on the Teensy side and see it work perhaps with read and write from both sides. Then the parallel PORT pins will be easier to do picking up from the Teensy.

  9. #9
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,051
    BTW - the Z80 is @5V … hopefully it will register the 3.3V as hugh

  10. #10
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    193
    Quote Originally Posted by Neon2 View Post
    For Teensy 3.5 and Arduino Sketch development where can I find the Arduino command/instruction set and the function use documentation?
    Here:
    https://www.arduino.cc/reference/en/

    Small code snippet to show fast read of 8 bits, with Teensy3.5/3.6 PortD pins: I was reading D0-D7 from a video camera

    Code:
    // This way, data pins are all connected to T3.6 Port D
    #define D7  5 
    #define D6  21
    #define D5  20
    #define D4  6 
    #define D3  8 
    #define D2  7 
    #define D1  14
    #define D0  2 
    
    // Read a byte of the pixel data
    inline const uint8_t readPixel()
    {
    	return (GPIOD_PDIR & 0xFF);	// Read all pins of Port D at a time
    }

  11. #11
    Junior Member
    Join Date
    May 2019
    Posts
    8
    Hi XFer,

    Thank you for the code example. I have a couple of questions.

    I was stumped with the (GPIOD_PDIR) so I did some reading of the K64 and in the GPIO section I see this entry: [Addr 400F_F0D0 Port Data Input Register (GPIOD_PDIR) 32b Read initial:0000_0000h]

    This is a 32bit read of Port D, is the "& 0xFF" telling the processor you only want the lower 8 bits?

    How does the Arduino Sketch code know chip specific implementations like GPIOD_PDIR ?

    Thanks
    Last edited by Neon2; 06-07-2019 at 02:32 AM.

  12. #12
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    193
    Quote Originally Posted by Neon2 View Post
    This is a 32bit read of Port D, is the "& 0xFF" telling the processor you only want the lower 8 bits?
    Yes. Consider the K64/66 does not actually have 32 PortD pins, only 16 (PTD0-PRD15); and only 8 of them (PTD0-PTD7) are accessible from the Teensy header pins (others are connected to pads on the bottom face, less convenient).

    How does the Arduino Sketch code know chip specific implementations like GPIOD_PDIR ?
    Indeed this is Teensy-specific stuff. When you install Teensyduino, it adds quite some sources and headers to the Arduino environment, let's say "behind the scenes" since you don't explicitely include/link them.
    Many defines are there.
    GPIOD_PDIR is in "kinetis.h".
    I suggest having a look at the folder "Arduino/hardware/teensy/avr/core/teensy3".

    To find out which sources/headers etc. the compiler is actually using, I suggest enabling "Show verbose output during compilation" in Arduino IDE preferences, and examining the bottom window.

    Which leads me to the Arduino IDE... you may have noticed it's not the ideal programming environment.

    You can bypass all the Arduino IDE / sketches framework and use straight C++ (many infos across the forum) with your IDE of choice, or just switch to a more powerful IDE while remaining "Arduino-like".
    Many options here, too. Personally, I use Microsoft Visual Studio Community + VisualMicro plugin. Others use Visual Studio Code + the excellent free tool "VisualTeensy" by user Luni.
    https://forum.pjrc.com/threads/55796...dio-for-Teensy
    Last edited by XFer; 06-07-2019 at 08:14 AM. Reason: Grammar

  13. #13
    Junior Member
    Join Date
    May 2019
    Posts
    8
    Hi XFer,

    Thanks for the help.

    When I was looking at the K64 doc's I called up the Teensy 3.5 schematic (that was discussed in replies to me) and I saw that only a portion of the port was brought out.
    I'm curious as to what the " & 0xFF " do? Is it just an AND with FFh?

    Yes, there is way more "behind the scenes" than I thought. Right now I don't have enough info to build or code.

    I have no experience with C or C++, did lots of hardware designs and coded in assembler. I've done VB/VBA work so I am familiar with the older Visual Studio products.

    I took a look at the links you sent and I read the IDE Compiler vs. Arduino piece and then branched to the link from Defragster into the Luni "VisualTeensy".

    Lots of choices...

    Does the Visual Studio environment simplify using the Teensy such that it integrates the Teensyduino (behind the scenes stuff)?

    If one goes the C++ route does that directly unearth all the behind the scenes stuff ?

    Thank you.

  14. #14
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    193
    Quote Originally Posted by Neon2 View Post
    I'm curious as to what the " & 0xFF " do? Is it just an AND with FFh?
    Yes, it's a mask to extract only the less significative byte from the 32-bit PORTD.

    I have no experience with C or C++, did lots of hardware designs and coded in assembler
    You can still go the ASM route, but honestly, it's quite a task!

    Does the Visual Studio environment simplify using the Teensy such that it integrates the Teensyduino (behind the scenes stuff)?
    To have Visual Studio + VisualMicro or Visual Studio Code (a very different product, despite the name) + VisualTeensy work at all, you first need a working Arduino IDE + Teensyduino installation.
    Then, yes, each of the three solutions hides the Teensy-stuff from you (to a point, meaning that you can still use low-level Teensy-specific functions if you want).

    If one goes the C++ route does that directly unearth all the behind the scenes stuff ?
    The C++ route still uses Arduino and Teensyduino libraries/headers/macros, although much less "behind-the-scenes".
    If you really want to go low level, there's plain C and the NXP Kinetis SDK.

    But I can't help you about that: I stick to the Arduino/Teensyduino framework, myself (have enough of poking registers with PICs!).

  15. #15
    Junior Member
    Join Date
    May 2019
    Posts
    8
    Hi Folks,

    XFer, thank you for the above info. Pieces are starting to click together :-)

    I took a look at the Teensy Core Libraries, specifically "kinetis.h". Wow is all I can say. So I gather I'll be looking through the K64 manual for a while.

    New Questions.

    1). Is there a Raw SD Card Read/Write library for the Teensy 3.5 that understands LBA accesses (or sector numbers)? I don't want Fat as I want to define where the data goes.

    2). If there are such a SD R/W library(ies) are there any that integrate the DMA controllers?

    3). Which of these would be easier to learn for a newbie? VS+VisualMicro or Visual Studio Code ?

    Thank you

Posting Permissions

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