Go to Post You and I have never met, but I am certain that if we went to the same school, we would have been good friends. - Molten [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 20-12-2013, 16:18
RyanShoff RyanShoff is offline
Registered User
FRC #4143 (Mars Wars)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2012
Location: Metamora, IL
Posts: 147
RyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to behold
Analog potentiometer to counter

I'm trying to connect an analog pot to a counter to keep track of how many revolutions the pot has made. There are a just a few examples of this. Can anybody look at this class and see if there are obvious errors? I know AnalogTriggerOutput isn't the most tested code path.

getturns() currently doesn't return anything but zero. I want it to increase on a clockwise revolution and decrease on a counterclockwise revolution.

Code:
#include "AnalogChannelVolt.h"
#include <math.h>

static const float rev = 5.0;
static const float halfrev = rev/2;
static const float scale = rev/(4.8-.2);
static const int   ratio = 2; // ratio of pot to finished gear, must be int

#define INV



AnalogChannelVolt::AnalogChannelVolt(UINT8 modulenumber, UINT32 channel)
  : AnalogChannel(modulenumber, channel)
{
    m_trig = new AnalogTrigger(modulenumber, channel);
    m_trig->SetFiltered(true);
    m_trig->SetLimitsVoltage(0.5,4.5);

    m_count = new Counter();
    m_count->SetUpDownCounterMode();
    m_count->SetUpSource(m_trig, AnalogTriggerOutput::kRisingPulse);
    m_count->SetDownSource(m_trig, AnalogTriggerOutput::kFallingPulse);
    m_count->SetUpSourceEdge(true,false);
    m_count->SetDownSourceEdge(true,false);

    m_count->Reset();
    m_count->Start();
}

float AnalogChannelVolt::GetAverageVoltage()
{
    return GetVoltage();
}

void AnalogChannelVolt::ResetTurns()
{
    m_count->Stop();
    m_count->Reset();
    m_count->Start();
}

float AnalogChannelVolt::GetVoltage()
{
  float temp = AnalogChannel::GetVoltage();
  temp = (((temp - halfrev) * scale) + halfrev);  // scale
  if(temp < 0) temp = 0; // min
  if(temp > rev) temp = rev; // max
  temp = (temp / ratio) + ((m_count->Get() % ratio) * halfrev); // half scale
#ifdef INV
  temp = rev - temp; // inverse
#endif
  return temp;
}

int AnalogChannelVolt::getturns()
{
    return m_count->Get();
}
double AnalogChannelVolt::PIDGet()
{
  return GetVoltage();
}

AnalogChannelVolt::~AnalogChannelVolt()
{
  delete m_trig;
  delete m_count;
}
Ryan Shoff
4143
Reply With Quote
  #2   Spotlight this post!  
Unread 20-12-2013, 16:55
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,572
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Analog potentiometer to counter

I haven't played with Analog triggers for a few years, and that was in LabVIEW. I just pulled up my old LabVIEW code and it looks very similar to yours.

Are you sure the pot value is getting below 0.5v and above 4.5v? If it isn't the Analog Trigger won't trigger. It may also be usefull to look at the AnalogTrigger getInWindow and getTriggerState values, to see if it is the Analog Trigger that isn't triggering, or the counter that isn't counting.
Reply With Quote
  #3   Spotlight this post!  
Unread 20-12-2013, 18:41
RyanShoff RyanShoff is offline
Registered User
FRC #4143 (Mars Wars)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2012
Location: Metamora, IL
Posts: 147
RyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to behold
Re: Analog potentiometer to counter

The analog voltage goes between .2 and 4.8v. I can see getinwindow change state once a rotation. I'm going to try just using the upsource just to see what happens. The FPGA code is not released, correct?
__________________
Ryan Shoff
4143 Mars/Wars
CheapGears.com
Reply With Quote
  #4   Spotlight this post!  
Unread 20-12-2013, 21:26
RyanShoff RyanShoff is offline
Registered User
FRC #4143 (Mars Wars)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2012
Location: Metamora, IL
Posts: 147
RyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to behold
Re: Analog potentiometer to counter

changing
Code:
m_count->SetUpSource(m_trig, AnalogTriggerOutput::kRisingPulse);
to
Code:
m_count->SetUpSource(m_trig, AnalogTriggerOutput::kState);
gets the counter moving. Of course that doesn't make it functional.

I think AnalogTriggerOutput::kRisingPulse is implemented in the FPGA which I can't see inside.
__________________
Ryan Shoff
4143 Mars/Wars
CheapGears.com
Reply With Quote
  #5   Spotlight this post!  
Unread 21-12-2013, 00:55
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,572
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Analog potentiometer to counter

Quote:
Originally Posted by RyanShoff View Post
The FPGA code is not released, correct?
That's correct.
Reply With Quote
  #6   Spotlight this post!  
Unread 22-12-2013, 01:34
Joe Hershberger Joe Hershberger is offline
National Instruments
AKA: jhersh
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: Nov 2005
Rookie Year: 1997
Location: Austin, TX
Posts: 148
Joe Hershberger is a name known to allJoe Hershberger is a name known to allJoe Hershberger is a name known to allJoe Hershberger is a name known to allJoe Hershberger is a name known to allJoe Hershberger is a name known to all
Re: Analog potentiometer to counter

Quote:
Originally Posted by RyanShoff View Post
changing
Code:
m_count->SetUpSource(m_trig, AnalogTriggerOutput::kRisingPulse);
to
Code:
m_count->SetUpSource(m_trig, AnalogTriggerOutput::kState);
gets the counter moving. Of course that doesn't make it functional.

I think AnalogTriggerOutput::kRisingPulse is implemented in the FPGA which I can't see inside.
The rising / falling pulse only indicates a transition from one sample to the next that entirely leaps over the window. Given how large you set the window and the impedance of the sensor it is unlikely that the signal is fast enough to make that leap. This is likely the reason you are seeing 0 all the time. It otherwise appears that you have it configured correctly. You can also try lowering the sampling rate to affect how quickly the signal changes from one sample to the next. Be aware the sample rate will affect every channel on that module.
Reply With Quote
  #7   Spotlight this post!  
Unread 23-12-2013, 00:32
RyanShoff RyanShoff is offline
Registered User
FRC #4143 (Mars Wars)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2012
Location: Metamora, IL
Posts: 147
RyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to behold
Re: Analog potentiometer to counter

I'm making progress. I does look like the signal does not transition fast enough to completely jump the window.

One other question, Is there a maximum number of AnalogTriggers available in the FPGA?

I tried hooking up two AnalogTriggers (with different windows) to the same channel and that seems to work.
__________________
Ryan Shoff
4143 Mars/Wars
CheapGears.com
Reply With Quote
  #8   Spotlight this post!  
Unread 24-12-2013, 08:44
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,752
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Analog potentiometer to counter

The documentation for the LV VIs state that you have eight analog triggers.

Greg McKaskle
Reply With Quote
  #9   Spotlight this post!  
Unread 24-12-2013, 23:28
RyanShoff RyanShoff is offline
Registered User
FRC #4143 (Mars Wars)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2012
Location: Metamora, IL
Posts: 147
RyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to behold
Re: Analog potentiometer to counter

I finally got the AnalogTriggers working well counting rotations.

I was using these pots:
http://www.mouser.com/ProductDetail/...1hvDsngmWGdg==

The key was reducing the sample rate to 1000 Hz.
Code:
this->GetModule()->SetSampleRate(1000);
This value was determined experimentally.

At the max rpm of the sensor (500 rpm) that is still 120 samples per rev.

I tested two implementations. Both worked fine.

One used the rising/falling pulse feature to catch the rollover.

The other used two AnalogTriggers to convert the pot to a quadrature signal. That was fed into an Encoder object.

Code is here:
https://github.com/FRC-Team-4143/TMW...hannelVolt.cpp
__________________
Ryan Shoff
4143 Mars/Wars
CheapGears.com
Reply With Quote
  #10   Spotlight this post!  
Unread 25-12-2013, 12:08
Joe Hershberger Joe Hershberger is offline
National Instruments
AKA: jhersh
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: Nov 2005
Rookie Year: 1997
Location: Austin, TX
Posts: 148
Joe Hershberger is a name known to allJoe Hershberger is a name known to allJoe Hershberger is a name known to allJoe Hershberger is a name known to allJoe Hershberger is a name known to allJoe Hershberger is a name known to all
Re: Analog potentiometer to counter

Quote:
Originally Posted by RyanShoff View Post
I finally got the AnalogTriggers working well counting rotations.
Congratulations!
Reply With Quote
  #11   Spotlight this post!  
Unread 25-12-2013, 20:56
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,572
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Analog potentiometer to counter

Quote:
Originally Posted by RyanShoff View Post
The key was reducing the sample rate to 1000 Hz.
Code:
this->GetModule()->SetSampleRate(1000);
This value was determined experimentally.

At the max rpm of the sensor (500 rpm) that is still 120 samples per rev.
Another option might be to use the averaged value, rather then the filtered value. You could use either 5 or 6 bits of averaging, and not change the sample rate of the module. This might occasionally have trouble at the transitions, however.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 14:37.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi