element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Digital Fever
  • Challenges & Projects
  • Project14
  • Digital Fever
  • More
  • Cancel
Digital Fever
Blog The Logical Project
  • Blog
  • Forum
  • Documents
  • Events
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Digital Fever requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: dougw
  • Date Created: 7 Mar 2021 8:05 PM Date Created
  • Views 630 views
  • Likes 20 likes
  • Comments 12 comments
  • doug wong
  • slotted opto coupler
  • quadrature decoder
  • encoder wheel
  • phototransistor
  • psoc 4200
  • psoc creator
  • bcd counter
  • logic design
  • 7 segment decoder
  • binary counter
  • digitalfeverch
  • quadrature encoder
  • vb6
Related
Recommended

The Logical Project

dougw
dougw
7 Mar 2021

Intro

I always had a lot of fun designing digital circuits that used Boolean logic, but these days it is rare to see designs with lots of discrete gates. With this little project I'm going to have some fun designing a quadrature decoder and display using logic gates and flip-flops. It will actually use 9 inverters, 19 AND gates, 13 OR gates, 4 T  flip-flops, and 2 SR flip-flops for a total of 46 logic devices. If it was implemented with TTL or 4000 series chips it could take a dozen chips, but in this project I will implement all of these gates and their interconnections in a single PSoC 4 chip listed at $2.52 by the manufacturer. The 44+ pin PSoC 4 modulePSoC 4 module below allows one of these chips to plug into a breadboard.

Most of the connections to the logic module in this image are just for demonstration purposes. The decoder only really needs 2 input wires and the 7 output resistors driving the 7 segment display.

I actually tried several different implementations of the quadrature decoder function because it was easy to make changes without any physical rewiring.

The complete project implements:

  • a quadrature encoding wheel and circuit
  • a quadrature decoding circuit
  • a 4 bit binary counter
  • a BCD to 7 segment decoder

I ordered digital chips to do the counting and 7 segment decoding, but they have not arrived, so all of the logic is implemented in the PSoC device.

This blog will cover the following topics:

  • an explanation of how the circuit is designed and programmed into the PSoC chip using PSoC Creator
  • a description of a simple quadrature decoder circuit
  • a Visual Basic simulation of a simple quadrature decoder
  • a description of quadrature signals and a more accurate quadrature decoder circuit
  • a brief description of a 4 bit binary counter
  • a brief description of a BCD to 7 segment decoder

 

Demo

This first video shows the system in operation so it is clear what is being attempted and the components involved.

The slotted opto-couplers did not arrive so I used a pair of phototransistors instead.

You don't have permission to edit metadata of this video.
Edit media
x
Upload Preview

1st Schematic Operation

The second video describes the first (simple) quadrature decoder I devised by using a visual Basic program to simulate the circuit. VB6 is a great tool for quickly implementing this simulation since it is can be used as a visual object oriented, event driven language. Each gate and its inputs and output are all visual and the code is a simple one line indicating what happens to the output based on what the inputs are. The gate code is automatically executed whenever an input changes so the program does not need a state machine. If an output changes because an input changed, and this output happens to be the input to another gate, it will automatically trigger the gate code for that next stage. No real program planning is needed:

You don't have permission to edit metadata of this video.
Edit media
x
Upload Preview

2nd Schematic Operation

I was only going to do the circuit above, but couldn't resist trying to design a quadrature decoder that could handle transition noise better.

I did implement the circuit above and it works okay, but it is possible to get counting pulses by rocking the wheel without rotating it.

The third video explains this improved design and delves into the signals involved in quadrature decoding with the more accurate decoder circuit:

You don't have permission to edit metadata of this video.
Edit media
x
Upload Preview

PSoC Creator

This circuit counts pulses accurately in both directions and does not count pulses unless the wheel is actually rotating.

The last video shows how easy it is to design with logic in PSoC Creator:

You don't have permission to edit metadata of this video.
Edit media
x
Upload Preview

 

PSoC Creator makes designing with logic easy and fun. It is very visual, very fast, drag-and-drop, performs a lot of sanity checks when compiling, and any changes needed can be implemented without doing any physical rewiring. I wouldn't normally use it strictly for implementing hardware gates since the software side is so easy and powerful as well, but it is a pretty cost effective solution even if only used for hardware logic, especially because it can handle a large range of supply voltages and has a nice strong output current capability.

 

Schematics:

 

Software (VB6 Emulator):

Private Sub A_Click()
    If A.Text = "0" Then A.Text = "1" Else A.Text = "0"
    DoEvents
End Sub
Private Sub B_Click()
    If B.Text = "0" Then B.Text = "1" Else B.Text = "0"
    DoEvents
End Sub


Private Sub A_Change()
    If A.Text = "1" Then AI.Text = "0" Else AI.Text = "1"
    If A.Text = "1" And B.Text = "1" Then Clock.Text = "1" Else Clock.Text = "0"
    DoEvents
End Sub
Private Sub B_Change()
    If B.Text = "1" Then BI.Text = "0" Else BI.Text = "1"
    If A.Text = "1" And B.Text = "1" Then Clock.Text = "1" Else Clock.Text = "0"
    DoEvents
End Sub


Private Sub AI_Change()
    If AI.Text = "1" Then AII.Text = "0" Else AII.Text = "1"
    If BII.Text = "1" And AI.Text = "1" Then BIIN.Text = "0" Else BIIN.Text = "1"
    If AI.Text = "1" And AIINN = "1" And BI.Text = "1" Then Up.Text = "0" Else Up.Text = "1"
    If AI.Text = "1" And BIINN = "1" And BI.Text = "1" Then Down.Text = "0" Else Down.Text = "1"
    DoEvents
End Sub


Private Sub BI_Change()
    If BI.Text = "1" Then BII.Text = "0" Else BII.Text = "1"
    If AII.Text = "1" And BI.Text = "1" Then AIIN.Text = "0" Else AIIN.Text = "1"
    If BI.Text = "1" And AIINN = "1" And AI.Text = "1" Then Up.Text = "0" Else Up.Text = "1"
    If AI.Text = "1" And BIINN = "1" And BI.Text = "1" Then Down.Text = "0" Else Down.Text = "1"
    DoEvents
End Sub
Private Sub AII_Change()
    If AII.Text = "1" And BI.Text = "1" Then AIIN.Text = "0" Else AIIN.Text = "1"
    DoEvents
End Sub
Private Sub BII_Change()
    If BII.Text = "1" And AI.Text = "1" Then BIIN.Text = "0" Else BIIN.Text = "1"
    DoEvents
End Sub
Private Sub AIIN_Change()
    If AIIN.Text = "1" And BIINN.Text = "1" Then AIINN.Text = "0" Else AIINN.Text = "1"
    DoEvents
End Sub
Private Sub BIIN_Change()
    If BIIN.Text = "1" And AIINN.Text = "1" Then BIINN.Text = "0" Else BIINN.Text = "1"
    DoEvents
End Sub
Private Sub AIINN_Change()
    If BIIN.Text = "1" And AIINN.Text = "1" Then BIINN.Text = "0" Else BIINN.Text = "1"
    If BI.Text = "1" And AIINN = "1" And AI.Text = "1" Then Up.Text = "0" Else Up.Text = "1"
    DoEvents
End Sub
Private Sub BIINN_Change()
    If AIIN.Text = "1" And BIINN.Text = "1" Then AIINN.Text = "0" Else AIINN.Text = "1"
    If AI.Text = "1" And BIINN = "1" And BI.Text = "1" Then Down.Text = "0" Else Down.Text = "1"
    DoEvents
End Sub
Private Sub DownDir_Click()
    Direction.Text = "0"
    Timer1.Enabled = True
End Sub


Private Sub StopCmd_Click()
    Timer1.Enabled = False
End Sub


Private Sub Timer1_Timer()
    State = Val(State.Text)
    If Direction.Text = "0" Then
        If State = 0 Then
            A.Text = "0"
            B.Text = "0"
        End If
        If State = 1 Then
            A.Text = "1"
            B.Text = "0"
        End If
        If State = 2 Then
            A.Text = "1"
            B.Text = "1"
        End If
        If State = 3 Then
            A.Text = "0"
            B.Text = "1"
        End If
    Else
        If State = 0 Then
            A.Text = "0"
            B.Text = "0"
        End If
        If State = 1 Then
            A.Text = "0"
            B.Text = "1"
        End If
        If State = 2 Then
            A.Text = "1"
            B.Text = "1"
        End If
        If State = 3 Then
            A.Text = "1"
            B.Text = "0"
        End If
    End If
    State = State + 1
    If State > 3 Then State = 0
    State.Text = Str(State)
    DoEvents
    DoEvents
End Sub




Private Sub UpDir_Click()
    Direction.Text = "1"
    Timer1.Enabled = True
End Sub

 

Summary

This project was a lot of fun. I got to design and print an encoder wheel, whip up a VB program and play with logic design - all in the process of figuring out a bit of a brain teaser circuit.

Although the slotted opto-couplersslotted opto-couplers never arrived, a couple of 40 year old phototransistors from the parts bin worked well enough to demonstrate quadrature encoding. I wasn't originally planning to implement a binary counter or 7 segment decoder within the PSoC, but the logic chips did not arrive either. Fortunately the PSoC had plenty of resources to implement these functions in addition to the quadrature decoder. This extra custom logic made the design and troubleshooting work a bit more involved, but it simplified the hardware build, and correcting logic issues was actually very easy.

PSoC Creator has a very nice user interface which made implementing the circuit and making changes really intuitive. I didn't touch on its software programming capabilities because this project was specifically avoiding software, but that aspect of PSoC Creator is also very slick and it allows very productive code generation and debugging.

 

Relevant Links:

Digital Fever

Project14 | Winners Announcement: Digital Fever: From Simple Gates to FPGA and Beyond!

Anonymous

Top Comments

  • DAB
    DAB over 1 year ago +5

    Very good project Douglas.

     

    I first ran into quadrature circuits back in 1972 when I had to interface three stepper motors to counters.

    The motors controlled a three axis gimbal so we could control yaw, pitch…

  • javagoza
    javagoza over 1 year ago +5

    Great didactic introduction to quadrature encoders, Douglas!

    I didn't know what it was called but I'm doing just that for my Design Challenge project. I need to know the direction of movement of a sliding…

  • dougw
    dougw over 1 year ago in reply to neilk +5

    PSoC Creator is a hardware and software integrated development environment (IDE). It compiles hardware blocks and interconnections and programs them into the chip to configure its hardware functions. It…

  • navadeepganeshu
    navadeepganeshu over 1 year ago

    Super project dougw!
    I really liked how neat the built and structure of the project is. Inspirational!

    Haha, true. PSoC Creator is really amazing software and has a user-friendly interface. I used it for the first time and really liked it. Opens up infinite possibilities of coming up with unique circuits by (re)configuration of blocks.

    • Cancel
    • Up +3 Down
    • Reply
    • More
    • Cancel
  • dubbie
    dubbie over 1 year ago

    Doug,

     

    A great demonstrator project.

     

    Dubbie

    • Cancel
    • Up +4 Down
    • Reply
    • More
    • Cancel
  • dougw
    dougw over 1 year ago in reply to aspork42

    PSoC Creator is great - nothing like Vivado.

    Just draw a circuit and the tool does the rest.

    (almost ... you may have to watch one or two videos to get the hang of it, but I doubt there is anything simpler out there)

    • Cancel
    • Up +4 Down
    • Reply
    • More
    • Cancel
  • aspork42
    aspork42 over 1 year ago

    Cool project!

    I like PSoC Creator - it looks nice. I've never used it, so this is my first introduction. I had actually planned on doing almost the same project as part of Path II Programmable with the MiniZed, but struggled a lot with navigating the Vivado design suite. It was like taking an advanced physics class when I should have been in basic algebra... This makes me want to pick up a PSoC4 to play around with. Handling jitter can be pretty tough. I've worked on some vision systems that would freak out if they got jitter from a Z-Pulse on their encoder. Took a while to diagnose the issue...

    • Cancel
    • Up +5 Down
    • Reply
    • More
    • Cancel
  • dougw
    dougw over 1 year ago in reply to javagoza

    It sounds like an interesting project, I will check out your blogs.

    • Cancel
    • Up +3 Down
    • Reply
    • More
    • Cancel
>
Element14

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2022 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube