element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
  • Settings
Bluetooth Unleashed Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Bluetooth Unleashed Design Challenge
  • More
  • Cancel
Bluetooth Unleashed Design Challenge
Blog Smart exercise bike computer. Part #6: Experiments with mechanical tension measurement
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: yuritikhonov
  • Date Created: 15 Jun 2018 6:40 AM Date Created
  • Views 1632 views
  • Likes 7 likes
  • Comments 6 comments
  • bluetooth
  • potentiometer
  • freedom_development_platform
  • bluetooth_unleashed
  • frdm-k64f
  • frdm
  • design_challenges
  • frdm-kw41z
  • nxp
  • bt_exercise_bike
  • sport
Related
Recommended

Smart exercise bike computer. Part #6: Experiments with mechanical tension measurement

yuritikhonov
yuritikhonov
15 Jun 2018

Good day!

 

Today I want to continue series of articles about the secondary tasks of my project, next we have the measurement of tension.

 

As you may remember, in my program there is a variable “gear”, which, as the name implies, is responsible for the gear selected by the rider. I want to set this variable according to the actual tension on pedals of the exercise bike. There are several ways to solve this problem, I propose to consider each of them separately.

 

Ways of tension measurement

 

1. The way that is used on my old bike computer – do nothing and assume that the rider always rides in the 6th gear. I believe that this way of measuring is unacceptable, otherwise the article would not have been published today!

 

2. Manual switching gears using the exercise bike computer buttons. Strangely enough, but from the very beginning, I wanted to switch gears in this way. The drawbacks of this method are obvious, but it has one undeniable plus – when it is used you do not need to make any changes to the design of the exercise bike, for this reason I do not plan to completely abandon it.

image

 

3. Determining the position of the tension knob with the help of the rotary switch. This method suggests itself – the tension knob has 8 positions (gears), why not just add one contact group to each position? The reasons for not using this method are several:

  • in the body of the exercise bike there is very little space for the installation of the rotary switch;
  • from the rotary switch will go 9 wires, which must be pulled through the entire exercise bike;
  • these 9 wires still need to be connected to the computer, so we lose a significant part of the free lines of our microcontroller;
  • rotary switches do not allow to take into account "fractional" gears (see below).

image

 

4. The drawbacks of the rotary switch method do not impact the method for selecting gears  by means of a potentiometer. When this method is implemented, the potentiometer is installed closely to the tension mechanism (rather than to the tension knob!) This achieves the maximum measurement accuracy (since in this case there is practically no backlash of the mechanism). The main drawback of the method is the complexity of its implementation, caused by the need to make changes in the design of the exercise bike.

image

 

For my experiments today, I decided to implement the 2-nd and 4-th ways, as the most interesting (in my opinion).

 

Experiment with buttons

 

The use of buttons is the easiest way to point to the computer in which gear the rider is riding. As already mentioned above, despite all the obvious drawbacks, this method has one important feature – no need to make changes in the design of the exercise bike. And this means that in the future I will be able to transfer my computer to a new exercise bike without any difficulties.

 

Below I present the code realizing the possibility of switching gears using the SW2 and SW3 buttons on my  FRDM-K64FFRDM-K64F board(in the future I will definitely transfer this program to  FRDM-KW41ZFRDM-KW41Z

 

// editing gear value (G) by buttons SW2 and SW3
float button_to_gear(float value)
{
    if (gpio::read(SW2)) // gear UP button
    {
        value += 1.0f;
        while (gpio::read(SW2)) __ASM("NOP");
    }
    if (gpio::read(SW3)) // gear DOWN button
    {
        value -= 1.0f;
        while (gpio::read(SW3)) __ASM("NOP");
    }
    
    if (value < 1) value = 1.0f;
    if (value > 8) value = 8.0f;
    
    return value;
}

 

Experiment with potentiometer

 

To conduct this experiment, I specifically asked my colleagues to pick up for me some good potentiometer. They offered me an USSR slider potentiometer [SP3-23A]. This potentiometer has a fairly large size, which simplifies its installation on exercise bike. I secured it by screw connection through a foil-shaped PCB. The rod between the potentiometer stick and the tension mechanism of my exercise bike was made from two large clerical clips welded together:

image

 

To carry out the experiment it is necessary to determine the voltage U_adc(G) at the input of the ADC using the formula:

 

U_adc (G) = R1 (L) / (R1 (L) + R2) * U2

 

For this we have the following data:

  • resistance of resistor R2 = 20 kOhm;
  • voltage at the input of circuit U2 = 3.3 V;
  • on the first gear (G = 1), the resistance of potentiometer R1(G1) = 2.72 kOhm;
  • on the eight gear (G = 8), the resistance of potentiometer R1 (G8) = 9.96 kOhm.

 

U_adc(G1) = 2.72 / (2.72+20.00) * 3.3 = 0.32 V

U_adc(G8) = 9.96 / (9.96+20.00) * 3.3 = 1.10 V

 

We get the voltage difference U_adc(G8) – U_adc(G1) of the order of 0.78 V, which corresponds to ~ 22% of the ADC measurement range at a reference voltage level of 3.3 V or ~ 60% at a reference voltage level of 1.2 V.

 

Now, knowing that our microcontroller has a 16-bit ADC with a reference voltage of 1.2 V, we can determine gear (G) from the ADC value (V). Without going into the details of calculations, I will give the formula I obtained:

 

G = 0.002629 * V – 1.871

 

For tests of the developed system I wrote the following program code:

 

// convert from ADC value to gear value (G)
float adc_to_gear(void)
{
    float value = adc::read(ADC_TENSION);
    value = value*0.002629.0f-1.871f;

    if (value < 1) value = 1.0f;
    if (value > 8) value = 8.0f;
    
    return value;
}

// get analog-data from line 'pin'
int adc::read(char pin)
{
    // invalid data
    if (pin != ADC_TENSION) return -1;
    
    // 'pin' onfiguration
    adc16_channel_config_t hadc_ch;    
    hadc_ch.channelNumber = ADC_TENSION_CH;
    hadc_ch.enableInterruptOnConversionCompleted = false;
    hadc_ch.enableDifferentialConversion = false;

    // starting measurements
    ADC16_SetChannelConfig(ADC_BASE, ADC_TENSION_GR, &hadc_ch);
    
    // waiting for new analog value
    while (!ADC16_GetChannelStatusFlags(ADC_BASE, ADC_TENSION_GR) & kADC16_ChannelConversionDoneFlag)
    {
        __ASM("NOP");
    }
    
    // return measured analog value
    return ADC16_GetChannelConversionValue(ADC_BASE, ADC_TENSION_GR);
}

 

Note that the variable “gear” now is float type, which means that I do not just define the speed depending on the digit on the tension knob scale, as I did before, I define "speed with a fractional part", because I know for sure in which point the tension mechanism is located.

 

Conclusion

 

Today I managed to execute one more item from my plan Maximum – to determine the “gear” in which the rider is riding. The only thing I would like to work on is the rod of the potentiometer. I made it from clerical paper clips and now their stiffness seems to me insufficient. Perhaps in the future I will make it from a welding electrode.

 

The program obtained in the course of today's experiments, as always, is available in [the official project repository]. If you, for example, have a question, how in my program is made the choice of one or another way of determining tension be sure to check it out!

 

Thanks for reading and have a nice day!

  • Sign in to reply

Top Comments

  • DAB
    DAB over 7 years ago +3
    Nice update. DAB
  • genebren
    genebren over 7 years ago +2
    Nice update to your design challenge project. I really like the clever approach that you took to determine the active 'gear' on your exercise bike. Your multiple step experiment was a good example of how…
  • yuritikhonov
    yuritikhonov over 7 years ago in reply to genebren +2
    Thanks Gene! This approach I use in everything, I even make tea with preliminary calculations
  • yuritikhonov
    yuritikhonov over 7 years ago in reply to DAB

    Thanks DAB!

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 7 years ago

    Nice update.

     

    DAB

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • yuritikhonov
    yuritikhonov over 7 years ago in reply to genebren

    You correctly understood me! I often find in simple everyday things the manifestations of the fundamental laws of physics and mathematics, such small discoveries make me happy much more than any things that can be bought for money.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 7 years ago in reply to yuritikhonov

    Yuri,

    I had not thought of creating a flowchart for making tea, but I guess that it might help.  My daughter-in-law has a very extensive tea collection and she has even printed up a multiple page list, broken into categories and sub-categories.  It always impresses me as I look through all the choices.

    Gene

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • yuritikhonov
    yuritikhonov over 7 years ago in reply to genebren

    Thanks Gene!

    This approach I use in everything, I even make tea with preliminary calculations image

    • Cancel
    • Vote Up +2 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 © 2025 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