CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Need help with Chinese Torque Sensor.
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Dec 30, 2021 7:09 am     Reply with quote

You just put pictures on any of the free picture hosting sites, and post the
link here. Very Happy
rudy



Joined: 27 Apr 2008
Posts: 167

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Thu Dec 30, 2021 7:13 am     Reply with quote

Rsrsrsrs.

Will do it! Just wait for the part number!

Thank you!
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Dec 30, 2021 8:19 am     Reply with quote

This torque sensor unit could be a 'custom' unit, made for a specific client that specified the +-18 volt differential output, and has now found it's way onto the 'surplus' market.
There may or may not be a real RS-485 interface,pictures from all side would really help,or a link to the website where it was purchased.

Jay
rudy



Joined: 27 Apr 2008
Posts: 167

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Fri Jan 21, 2022 11:31 am     Reply with quote

Well, Ttelmah:

I had made tons of trying, but with the original design, using the 16F876A @4Mhz processor clock, it is too slow! So, I added a frequency divider, a simple one, using an ordinary CD4017, that improved a lot the 16F876A performance, because it seems to me that is not able to handle such 10kHz +-5kHz signal. Also tried the 16 rise edges CCP configuration, but also it is not a good solution, due to resolution lost.

At the end, I reassembled the circuit with an 18F26K22, and yes, the performance is strongly improved. It is able to handle the top most 15Khz signal, on each rising edge with no effort.

Really seems to me to be a good choice!

I did the start code just to read the frequency output of the torque transducer, not the math yet (this is much easier once that the main “gears” are running well). So, my code is as below:
Code:

 #include <18F26K22.h>
#fuses NOWDT, NOFCMEN, NOIESO, NOCPD, NOPROTECT, NOLVP, NODEBUG, PUT, BROWNOUT, NOMCLR
#use DELAY(INTERNAL=64MHz)
#use I2C(MASTER, SDA=PIN_B0, SCL=PIN_B1)

#byte PORTA=0xF80
#byte PORTB=0xF81
#byte PORTC=0xF82
#byte PORTE=0xF84

//VARIÁVEIS DE SISTEMA
int PAGE=100, DPY=0, D1=8, D2=8, D3=8, D4=8, D5=8;
int FLGS0, AUXS0, AUXS1, CCP_AUX=0;
long PEEK=0, THSD=0, T1_TKS, CCP_RES;
int32 CCP_MEDIA;

//EEPROM ADRESSES
//0X00 -> RESERVED
//0X01 -> PEEK LSB
//0X02 -> PEEK MSB
//0X03 -> THSD LSB
//0X04 -> THSB MSB

#bit DGT1=porta.0
#bit DGT2=portc.1
#bit DGT3=porta.2
#bit DGT4=portc.0
#bit DGT5=porta.5
#bit SCK=portb.6
#bit RCK=portb.5
#bit LED0=portc.4

#bit STR=FLGS0.0
#bit EE_UPD=FLGS0.1
#bit CCP_RDY=FLGS0.2

int N_S[12]=
   {
   //ABCDEFGP
   0b00000011,  //0X00H - 0 - 0
   0b10011111,  //0X01H - 1 - 1
   0b00100101,  //OX02H - 2 - 2
   0b00001101,  //0X03H - 3 - 3
   0b10011001,  //0X04H - 4 - 4
   0b01001001,  //0X05H - 5 - 5
   0b01000001,  //0X06H - 6 - 6
   0b00011111,  //0X07H - 7 - 7
   0b00000001,  //0X08H - 8 - 8
   0b00001001,  //0X09H - 9 - 9
   0b00111001,  //0X0AH - º - 10
   0b11111111  //0X0BH - BLANK - 11
   };
void S_595(int NBR)
   {
   int i=0;
   if(STR)NBR=NBR&0b11111110;
   for(i=0;i<8;i++)
      {
      output_bit(PIN_B7,shift_right(&NBR,1,0));
      SCK=1;
      SCK=0;
      }
   RCK=1;
   }
void EE_WRT()
   {
   AUXS0=MAKE8(PEEK,0);
   WRITE_EEPROM(0X01,AUXS0); //0X01 -> PEEK LSB
   AUXS0=MAKE8(PEEK,1);
   WRITE_EEPROM(0X02,AUXS0); //0X02 -> PEEK MSB
   AUXS0=MAKE8(THSD,0);
   WRITE_EEPROM(0X03,AUXS0); //0X03 -> THSD LSB
   AUXS0=MAKE8(THSD,1);
   WRITE_EEPROM(0X04,AUXS0); //0X04 -> THSB MSB
   EE_UPD=0;
   }
void SEND_DATA(int ADDRESS, int CMMD, long VALUE)
   {
   i2c_start();
     i2c_write(ADDRESS); // I2C ADDRESS
     i2c_write(CMMD);      // COMMAND
     AUXS0=MAKE8(VALUE,0);
     AUXS1=MAKE8(VALUE,1);      
     i2c_write(AUXS1);   // MSB
     i2c_write(AUXS0);   // LSB
    i2c_stop();   
   }
void DECODE()
   {
      
         CCP_RES=T1_TKS;
   CCP_AUX++;
   CCP_RES=2000000/CCP_RES;
   CCP_MEDIA=CCP_MEDIA+CCP_RES;
   if(CCP_AUX==199)
      {
      CCP_AUX=0;
      CCP_MEDIA/=200;
      AUXS1=MAKE8(CCP_MEDIA,1);
      AUXS0=MAKE8(CCP_MEDIA,0);
      CCP_RES=MAKE16(AUXS1,AUXS0);   
      D1=CCP_RES/10000;
      D2=CCP_RES/1000-D1*10;
      D3=CCP_RES/100-D1*100-D2*10;
      D4=CCP_RES/10-D1*1000-D2*100-D3*10;
      D5=CCP_RES-D1*10000-D2*1000-D3*100-D4*10;
      }
   CCP_RDY=0;
   }
void main()
   {
   SETUP_ADC_PORTS(NO_ANALOGS);
    SETUP_COMPARATOR(NC_NC_NC_NC);
      SETUP_COUNTERS(RTCC_INTERNAL,RTCC_DIV_128|RTCC_8_BIT);
    SETUP_TIMER_1(T1_INTERNAL|T1_DIV_BY_8);
      SETUP_TIMER_2(T2_DISABLED,0xFF,16);
   SET_TRIS_A(0b00000000); 
   SET_TRIS_B(0b00011111);
   SET_TRIS_C(0b11111100);
   SETUP_CCP1(CCP_CAPTURE_RE);
   ENABLE_INTERRUPTS(INT_RTCC);
   ENABLE_INTERRUPTS(INT_CCP1); //INABLE INFRARED INTERRUPTION
   ENABLE_INTERRUPTS(GLOBAL); 
loop:
     while(TRUE)) //PG NORMAL DE TRABALHO
      {
      if(CCP_RDY)DECODE();
      }
      }
goto loop;
   }
#INT_RTCC
void RTCC_ISR()
   {
   RCK=0;
    DGT1=0;
    DGT2=0;
    DGT3=0;
    DGT4=0;
     DGT5=0;
    switch(DPY)            
      {
      case 0:
         DPY++;
         S_595(N_S[D1]);
         DGT1=1;
         break;
      case 1:
         DPY++;
         S_595(N_S[D2]);
         DGT2=1;               
         break;
      case 2:
         DPY++;
         S_595(N_S[D3]);
         DGT3=1;
         break;
      case 3:
         DPY++;
         S_595(N_S[D4]);
         DGT4=1;
         break;
      case 4:
         DPY=0;
         S_595(N_S[D5]);
         DGT5=1;      
         break;
      }
   }
#INT_CCP1   //CCP1 INTERRUPTION SERVICE ROUTINE
void CCP1_ISR(void)
   {
   T1_TKS=GET_TIMER1(); //PEGA A QUANTIDADE DE TICKS DO TIMER 1
   SET_TIMER1(0); //ZERA TIMER1
   CCP_RDY=1;
   }


By the way, I asked to the Chinese team if is possible to have a torque transducer output changed to 5-15Khz straight, instead of 10kHz center frequency, once that I don’t need direction information. My guess is that it will not be possible due to the “bridge” effect. Lets see what they will answer.

As you and all others colleges aways do, if you have any TIPS, please advise.

Thank you!

Ttelmah wrote:
If you have ordered this thing, you must have had a web page that you
ordered it from, with some form of description/number. Where?.

Now, if it's output is +/-18v, this is not RS485.
You should really keep the signal at the high voltage till it reaches your
board and have a differential converter at this point to generate the logic
signal to the PIC.
If you expected it to be RS485, you must have had some 'expectation'
about the data stream you expected to see. Where did this come from?.
Honestly, the fastest and simplest thing to do will be to make a small
board that receives this differential signal, generates a TTL signal from this,
uses a PIC to time this, and generates the RS485 you expected to see
from this. Now if it says that it should be 5KHz to 15KHz, then the very
simplest way will be to time the pulse between two successive edges.

It sounds suspiciously to me as if this may be a bi-directional sensor,
so it can measure torque in both directions. So it gives 10KHz, with no
load, and goes to 5KHz for max torque in one direction, and 15KHz for
the same force in the opposite direction. Hence the 10KHz signal.
Now, using a 26K22, use a CCP module. Just capture the timer value
on each successive rising edge. Feed the timer used off Fosc, and at
your 64MHz, you will have a count of 12800 between successive edges
for 5KHz, and 4266 at 15KHz. 6400 at the no load state. Have this
being done in an interrupt from the CCP, so that the main code can just
read the count number and do the maths. The maths should be:
f=64000000/count
fdelta=f-10000
torque(nm)=fdelta/5

Big lesson here is to only use parts where good data is available. You
are now involved in the expense and time of having to decode this
signal. For a commercial product this will cost more than buying a
properly documented part. Sad
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Jan 21, 2022 2:05 pm     Reply with quote

The resolution is dependant on the clock frequency of the chip. You could
have simply gone to a much faster clock on the original chip, but the
PIC18 supports going much faster than the original PIC16, so going to
this helps the resolution massively.
rudy



Joined: 27 Apr 2008
Posts: 167

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Tue Feb 15, 2022 1:03 pm     Reply with quote

Hard to follow you Ttelmah!

Just a few weeks ago, I had the opportunity to have the final machinery information, where the TD will be installed! There are some mechanical issues that I need to consider!

First, there is a mechanical reduction of 1/71 turns in the input shaft.

Second, the output roll radius is 245mm.

So, if we consider these mechanical properties, for each 1Nm torque at the input shaft, the output force will be 29,55 Kg (kg is the desired unit). F=TxN/(Dxg) = 1 x 71 / 0,245 x 9,80665 = 29,55kg. In other hands, my desired resolution is 10Kg, and doing the math, for every 10kg load at the output shaft, 0,3384 N input torque is required, and with a deviation of only 1,69Hz.

Well, it seems simple, but maybe I am doing something wrong with T1 calculation, that’s where I need your help.

At no load, the TD output is 10Khz or 0,1ms period. In this condition, with T1 running with 1:1 prescaler, the T1 ticks each 62,5 ns. Dividing the T1 period / TD period, we have 1600 ticks, and not 6400 as you mentioned, is it right?

The faster I run T1 better, and it is the limit I have at Fosc/4. With this condition, the resolution is larger than I need, or 34kg at the output shaft to cause necessary frequency drift to change T1 counting. I also think to divide the input frequency by 10, but I will also divide the output frequency drift, so there is no meaning to do this.

All this if for ask you to check if the T1 math I am doing is right! (4/Fosc) x Prescaler I think is the tick frequency.

Regards!

Ttelmah wrote:
If you have ordered this thing, you must have had a web page that you
ordered it from, with some form of description/number. Where?.

Now, if it's output is +/-18v, this is not RS485.
You should really keep the signal at the high voltage till it reaches your
board and have a differential converter at this point to generate the logic
signal to the PIC.
If you expected it to be RS485, you must have had some 'expectation'
about the data stream you expected to see. Where did this come from?.
Honestly, the fastest and simplest thing to do will be to make a small
board that receives this differential signal, generates a TTL signal from this,
uses a PIC to time this, and generates the RS485 you expected to see
from this. Now if it says that it should be 5KHz to 15KHz, then the very
simplest way will be to time the pulse between two successive edges.

It sounds suspiciously to me as if this may be a bi-directional sensor,
so it can measure torque in both directions. So it gives 10KHz, with no
load, and goes to 5KHz for max torque in one direction, and 15KHz for
the same force in the opposite direction. Hence the 10KHz signal.
Now, using a 26K22, use a CCP module. Just capture the timer value
on each successive rising edge. Feed the timer used off Fosc, and at
your 64MHz, you will have a count of 12800 between successive edges
for 5KHz, and 4266 at 15KHz. 6400 at the no load state. Have this
being done in an interrupt from the CCP, so that the main code can just
read the count number and do the maths. The maths should be:
f=64000000/count
fdelta=f-10000
torque(nm)=fdelta/5

Big lesson here is to only use parts where good data is available. You
are now involved in the expense and time of having to decode this
signal. For a commercial product this will cost more than buying a
properly documented part. Sad
rudy



Joined: 27 Apr 2008
Posts: 167

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Tue Feb 15, 2022 3:46 pm     Reply with quote

I made a excel spreadsheet, the best choice is to use T1 1:2 prescaler, and use 16th rise edge of the CCP.

Regards.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group