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
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • Experts & Guidance
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • 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
Personal Blogs
  • Members
  • More
Personal Blogs
Legacy Personal Blogs Vintage Turntable repair: Can I fix a Perpetuum Ebner from 1958 - part 6 - Speed Adjustment with Variable Duty Cycle
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 3 Mar 2015 7:50 PM Date Created
  • Views 741 views
  • Likes 2 likes
  • Comments 5 comments
  • hercules_launchpad
  • duty_cycle
  • audio
  • hack
  • vintage
  • turntable
  • internet_of_things
  • arm_cortex
  • motor_control_kit
  • texas_instruments
  • motor_control
  • shield
  • motor
  • arduino
  • streaming
Related
Recommended

Vintage Turntable repair: Can I fix a Perpetuum Ebner from 1958 - part 6 - Speed Adjustment with Variable Duty Cycle

Jan Cumps
Jan Cumps
3 Mar 2015

What happened before:

 

For almost a year I have a vintage turntable from Perpetuum Ebner at home.

It's not mine. It belongs to someone that asked me to fix it. And it turned out that fixing the motor would cost too much.

I asked the owner to collect the tt. That hasn't happened yet and the machine is collecting dust at my home.

 

So I'll take the freedom to attempt a non-intrusive repair with modern components. I'm also thinking about making it an Enchanted Objects Design Challenge.

 

In post 1 I present the turntable, talk about my previous repair attempts and brainstorm on some modding ideas.
In post 2 I'm measuring up the different gears, pulleys and wheels, and I calculate the speed of the original motor.

Post 3 is the first post on motor control. I'm reviewing the operation of the Infineon DC Motor Control Shield.

In post number 4  I'm using the enhanced PWM module of my The specified item was not found. Hercules LaunchPad to test drive the motor.

The table is spinning for the first time in post 5.


In this article I'm building a speed adjuster.

image

 

You can regulate the DC motor's speed by varying the duty cycle of the signal you send to the motor driver.

And that's what I'm doing here. I react on button pushes to increase or decrease the duty cycle, and  that speed up or slow down the motor.

 

This video is unavailable.
You don't have permission to edit metadata of this video.

 

 

I have documented the  Hercules LaunchPad configuration in part 4, so I won't repeat it here. Follow the steps in that article if you want to replicate the exercise to get PWM out of the LaunchPad.

Here, I'll explain my steps to influence the speed.

And that's straightforward. Once you have your PWM working, you can change it by calling a simple API function:

 

etpwmSetCmpA(etpwmREG1, uDutyCycle)

 

(If you are more into direct registry manipulation, that's possible too. Just have a peek at what's happening with etpwm->CMPA in the file etpwm.c. That file was generated automatically if you followed the steps in post 4)

 

In the drawing below, you see that when you slow down the PWM signal's duty cycle, the same happens to the output of the motor shield. The percentages of the half H-bridge's output signal is in sync with the signal coming from our LaunchPad.

image

 

Enabling the GIO API library and the two LaunchPad User Buttons

 

Most pins on the RM46 microcontroller are multiplexed. And the pins for the two user buttons are no exception to that.

image

Button A is connected to pin 55 . The pin can be used as

  • MIBSPI3NCS_0
  • AD2EVT
  • GIOB_2
  • EQEP1I

Button B is pin 41.

  • N2HET1_15
  • MIBSPI1NCS_4
  • ECAP1

 

For pin 55, the decision on the correct function is easy. The pin has a dedicated GIO port (GIOB pin 2), so we'll use that.

But you'll notice that when you go to the HALCoGen PINMUX tab, you can't select that particular pin:

image

That is because this particular pin has to be enabled via the special Pin Muxing options (I don't know why yet; I haven't read that part of the spec image ).

When you select the 'Use GIOB_2' box, the pin is magically selected on the previous tab.

image

 

We'll be able to check if the button is down when the following call returns FALSE:

 

gioGetBit(gioPORTB, 2)

 

 

We MUX button B as NHET (NHET1 pin 15). This port/pin combination can be used in the GIO API as a generic GIO pin.

 

image

This one is checked by calling:

 

gioGetBit(hetPORT1, 15)

 

 

We have to enable two additional drivers in HALCoGen (we enabled the PWM driver in part 4):

GIO, for two reasons. When you selecting a driver, HALCoGen generates the API code. And we need that API code to poll the button state.

The second reason is that we're accessing one of the GIO pins (GIOB_2 for button A).

NHET1, because we are accessing the pin NHET1_15 for button B.

In our code, we'll have to call the xxxInit() function of both NHET and GIO, so that these two periferals are in their start state and correctly initialized.

 

  gioInit(); // user button A is on the GIOB port, 2
  hetInit(); // user button B is on the HET1 port, 15

 

The only thing left now is to check the button at regular times, and adjust the speed based on that.

 

I used a variable to keep the button state.

uint32 uBtn_Usr = 0U;

 

When you click and release button A, the bit on position 0 is set. A click and release of button B sets bit 1.

I used a very naive debounce mechanism. I've intentionally kept that part of the code simple for this proto setup.

You can find it in the full code at the end.

 

When the firmware has detected that a button was clicked, it adjusts the PWM duty cycle (in my example, 40U is 1% change).

 

void adjustDutyCycle() {
  if ((uBtn_Usr & BTN_USRA) && (uDutyCycle < 4000U)) {
    uDutyCycle += 40;
  }


  if ((uBtn_Usr & BTN_USRB) && (uDutyCycle > 0U)) {
    uDutyCycle -= 40;
  }


  etpwmSetCmpA(etpwmREG1, uDutyCycle);
  uBtn_Usr = 0;
}

 

The effect of pushing the button B 2 times is shown on this scope capture:

image

 

The code:

 

#include "sys_common.h"
#include "etpwm.h"
#include "het.h"
#include "gio.h"


// buttons for speed up and down
uint32 uBtn_Usr = 0U;
#define BTN_USRA 1U
#define BTN_USRB 2U


uint16 uDutyCycle;


bool buttonCheck();
void adjustDutyCycle();


void main(void) {


  uDutyCycle = 2000U;
  gioInit(); // user button A is on the GIOB port, 2
  hetInit(); // user button B is on the HET1 port, 15
  etpwmInit();


  while (1) {
    if (buttonCheck()) {
      adjustDutyCycle();
    }
  }
}


bool buttonCheck() {
  static uint32 uBtn_Usr_Bounce = 0U;


  if ((!(uBtn_Usr_Bounce & BTN_USRA)) && !gioGetBit(gioPORTB, 2)) {
    uBtn_Usr_Bounce += BTN_USRA;
  }


  if ((!(uBtn_Usr_Bounce & BTN_USRB)) && !gioGetBit(hetPORT1, 15)) {
    uBtn_Usr_Bounce += BTN_USRB;
  }


  if ((uBtn_Usr_Bounce & BTN_USRA) && gioGetBit(gioPORTB, 2)) {
    uBtn_Usr += BTN_USRA;
    uBtn_Usr_Bounce -= BTN_USRA;
  }


  if ((uBtn_Usr_Bounce & BTN_USRB) && gioGetBit(hetPORT1, 15)) {
    uBtn_Usr += BTN_USRB;
    uBtn_Usr_Bounce -= BTN_USRB;
  }


  return (uBtn_Usr > 0);
}


void adjustDutyCycle() {
  if ((uBtn_Usr & BTN_USRA) && (uDutyCycle < 4000U)) {
    uDutyCycle += 40;
  }


  if ((uBtn_Usr & BTN_USRB) && (uDutyCycle > 0U)) {
    uDutyCycle -= 40;
  }


  etpwmSetCmpA(etpwmREG1, uDutyCycle);
  uBtn_Usr = 0;
}

 

disclaimers:

The trained eye will see that there is not much to learn in this code on proper state machine design and debouncing. So be it.

The variable for the button state doesn't have to be volatile, because I'm not setting it in an interrupt. It's only manipulated in the main processing thread.

 

Related posts
Vintage Turntable repair: Can I fix a Perpetuum Ebner from 1958 - part 1
Vintage Turntable repair: Can I fix a Perpetuum Ebner from 1958 - part 2 - Calculating the Motor Speed
Vintage Turntable repair: Can I fix a Perpetuum Ebner from 1958 - part 3 - Infineon Motor Driver shield
Vintage Turntable repair: Can I fix a Perpetuum Ebner from 1958 - part 4 - Hercules LaunchPad Enhanced PWM try-out
Vintage Turntable repair: Can I fix a Perpetuum Ebner from 1958 - part 5 - Yes I Can
Vintage Turntable repair: Can I fix a Perpetuum Ebner from 1958 - part 7 - Make Speed Sensor from Scrap Parts
Vintage Turntable repair: Can I fix a Perpetuum Ebner from 1958 - part 8 - Sample the Motor Speed with Microcontroller
  • Sign in to reply

Top Comments

  • DAB
    DAB over 8 years ago +1
    Nice detailed post. Once you get the motor settings down, have you considered using a Phase Locked Loop to maintain a steady speed for the motor? DAB
  • Jan Cumps
    Jan Cumps over 8 years ago in reply to DAB +1
    ... and the first results are in. I get a nice pulse for each turn of the wheel. It's currently 5V, so to feed the signal to the LaunchPad I have to recalc the resistors to a 3.3V config
  • martinvalencia
    martinvalencia over 8 years ago in reply to Jan Cumps +1
    excellent work, I'm anxious to see the results and the quality of the audio once implemented the feedback
  • martinvalencia
    martinvalencia over 8 years ago in reply to Jan Cumps

    excellent work, I'm anxious to see the results and the quality of the audio once implemented the feedback image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 8 years ago in reply to DAB

    ... and the first results are in. I get a nice pulse for each turn of the wheel.

    It's currently 5V, so to feed the signal to the LaunchPad I have to recalc the resistors to a 3.3V config

    image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 8 years ago in reply to DAB

    My first attempt will be with an IR tx/rx led pair that I removed from a defect video recorder.

    I hope that the small shiny strip that I glued on one of the spindles gives a clean enough signal to measure the rotations.

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 8 years ago in reply to DAB

    Yes, that's on the agenda.

     

    I'm going to try to measure the speed of the intermediate spindle (the one that has different diameters for 16/33/45/78 RPM).

    It has a direct relation to the motor speed regardless of the platter speed and is the best candidate for measurements.

    There is some room there to place a magnetic or optical sensor.

     

    Once I have that going, I can create that locked loop and adjust for speed drift.

     

    (edit: it's not going to be a phase locked loop, but a feedback and adjust mechanism)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 8 years ago

    Nice detailed post.

     

    Once you get the motor settings down, have you considered using a Phase Locked Loop to maintain a steady speed for the motor?

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

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 © 2023 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

  • X
  • Facebook
  • linkedin
  • YouTube