Fuzzy tech to mbed

09 Mar 2011

Hiya,

I'm new to mbed and have just managed to get a switch and LED operating. I'm trying to load a fuzzy tech programme in C to mbed and I can't compile it. Can anybody help? Thanks

09 Mar 2011

It's hard to help without seeing the code or at least knowing what errors you get. Try to provide more info (the more the better).

10 Mar 2011

Thanks Igor - this is the code produced by fuzzy tech - it's a simple analogue in analogue out to test with mbed. I don't know how to assign the input and output to the mbed 'pins'

Many Thanks Tony

/*---------------*/ /*--- fuzzyTECH 5.71 Professional Edition ---*/ /*----- License Number: FT 10002 87 ID ----*/ /*---------------*/ /*---- Code Generator: C Source Code ----*/ /*--- Code Generation Date: Tue Mar 08 23:51:50 2011 --*/ /*---- Fuzzy Logic System: ANALOGUE ---*/ /*- Performance Optimization Capabilities (Memory): 6 Bytes -*/ /*- Performance Optimization Capabilities (Runtime): 10 Points */ /*---------------*/ /*- (c) 1991-2007 INFORM GmbH, Pascalstr. 23, 52076 Aachen, Germany -*/ /*---------------*/

  1. define PROFESSIONAL
  2. define FTLIBC16
  3. include "ftlibc.h"
  4. define FUZZYDEFINED
  5. define FLAGSDEFINED
  6. include "ANALOGUE.h"

static FUZZY crispio[1+1];

static FUZZY fuzvals[3+3+0];

static double dcvs[1+1]; double * const pcvanalogue = dcvs;

static const FUZZY tpts[12] = { 0x0000, 0x0000, 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0xFFFF, 0x8000, 0xFFFF, 0xFFFF, 0xFFFF};

static const FUZZY xcom[3] = { 0x0000, 0x8000, 0xFFFF};

static const BYTE rt0[9] = { 0x00, 0x01, 0x03, 0x00, 0x01, 0x03, 0x00, 0x01, 0x05};

static const FRAT frat0[6] = { 0x0003, 0x0000, 0x0003, 0x0001, 0x0003, 0x0002};

static const FUZZY BVRCode[4] = { 0x0000, 0xFFFF, 0x0000, 0xFFFF};

static const double BVRShell[6] = { 0, 1, 2e-005, 0, 1, 2e-005};

FLAGS analogue(void) { crispio[0] = BVScaleShell2Code(&BVRCode[0*2], &BVRShell[0*3], dcvs[0], BVRCode[0*2+1]<MAXBVRANGE, MAXBVRANGE);

fuzptr = (PFUZZY) fuzvals; tpptr = (PFUZZY) tpts;

crisp = crispio[0]; bTNum = 3; flms();

fuzptr = (PFUZZY) fuzvals;

usNumber = 3; fratptr = (PFRAT) frat0; rtptr = (PFTBYTE) rt0; iBMin(); /* BSum-Min */

invalidflags = 0; fuzptr = &fuzvals[3]; xcomptr = (PFUZZY) xcom;

crispio[1] = 0x8000; bTNum = 3; defuzz = &crispio[1]; com();

dcvs[1] = BVScaleCode2Shell(&BVRCode[1*2], &BVRShell[1*3], crispio[1]); return invalidflags; }

void initanalogue(void) { /* check fuzzyTECH C Runtime Library version */ ftcr200706();

for (fuzptr = &fuzvals[3]; fuzptr <= &fuzvals[5];

  • fuzptr++ = 0); }

/*

------------
MemoryRAMROM
------------
Fuzzy Logic System32 (0020H)111 (006FH)
------------
Total32 (0020H)111 (006FH)
------------
  • /
10 Mar 2011

Here's the code properly formatted. Now I can actually read it.

/*-------------------------------------------------------------------------*/
/*------------------- fuzzyTECH 5.71 Professional Edition -----------------*/
/*--------------------- License Number: FT 10002 87 ID --------------------*/
/*-------------------------------------------------------------------------*/
/*---------------------- Code Generator: C Source Code --------------------*/
/*------------- Code Generation Date: Tue Mar 08 23:51:50 2011 ------------*/
/*---------------------- Fuzzy Logic System: ANALOGUE ---------------------*/
/*--------- Performance Optimization Capabilities (Memory): 6 Bytes -------*/
/*------- Performance Optimization Capabilities (Runtime): 10 Points ------*/
/*-------------------------------------------------------------------------*/
/*----- (c) 1991-2007 INFORM GmbH, Pascalstr. 23, 52076 Aachen, Germany ---*/
/*-------------------------------------------------------------------------*/

#define PROFESSIONAL
#define FTLIBC16
#include "ftlibc.h"
#define FUZZYDEFINED
#define FLAGSDEFINED
#include "ANALOGUE.h"

static FUZZY crispio[1+1];

static FUZZY fuzvals[3+3+0];

static double dcvs[1+1];
double * const pcvanalogue = dcvs;


static const FUZZY tpts[12] = {
  0x0000, 0x0000, 0x0000, 0x8000, 
  0x0000, 0x8000, 0x8000, 0xFFFF, 
  0x8000, 0xFFFF, 0xFFFF, 0xFFFF};

static const FUZZY xcom[3] = {
  0x0000, 0x8000, 0xFFFF};

static const BYTE rt0[9] = {
  0x00, 0x01, 0x03, 
  0x00, 0x01, 0x03, 
  0x00, 0x01, 0x05};

static const FRAT frat0[6] = {
  0x0003, 0x0000, 0x0003, 0x0001, 0x0003, 0x0002};

static const FUZZY BVRCode[4] = {
  0x0000, 0xFFFF, 
  0x0000, 0xFFFF};

static const double BVRShell[6] = {
  0, 1, 2e-005, 
  0, 1, 2e-005};


FLAGS analogue(void) {
  crispio[0] = BVScaleShell2Code(&BVRCode[0*2], &BVRShell[0*3], dcvs[0], BVRCode[0*2+1]<MAXBVRANGE, MAXBVRANGE);
  
  fuzptr = (PFUZZY) fuzvals;
  tpptr  = (PFUZZY) tpts;

  crisp = crispio[0];
  bTNum = 3;
  flms();

  fuzptr = (PFUZZY) fuzvals;

  usNumber = 3;
  fratptr  = (PFRAT)  frat0;
  rtptr   = (PFTBYTE) rt0;
  iBMin(); /* BSum-Min */

  invalidflags = 0;
  fuzptr       = &fuzvals[3];
  xcomptr      = (PFUZZY) xcom;

  crispio[1] = 0x8000;
  bTNum  = 3;
  defuzz = &crispio[1];
  com();

  dcvs[1] = BVScaleCode2Shell(&BVRCode[1*2], &BVRShell[1*3], crispio[1]);
  return invalidflags;
}

void initanalogue(void) {
  /* check fuzzyTECH C Runtime Library version */
  ftcr200706();

  for (fuzptr = &fuzvals[3];
       fuzptr <= &fuzvals[5];
       *fuzptr++ = 0);
}

/*
|----------------------------------------------------|
| Memory             |      RAM      |      ROM      |
|----------------------------------------------------|
| Fuzzy Logic System |    32 (0020H) |   111 (006FH) |
|----------------------------------------------------|
| Total              |    32 (0020H) |   111 (006FH) |
|----------------------------------------------------|
*/ 
10 Mar 2011

I have no idea what's this fuzzy thing but you definitely will have to do some porting as it seems to use some custom headers, types and functions. Or you can just start from scratch and use functionality provided by mbed libraries.

10 Mar 2011

Thanks Igor, I believe that this code can be downloaded to an MCU-96-166-320-C device. I understood that this C code would be ok for the mbed. A colleague has suggested Chris Styles at ARM might be able to help - I'll make contact with Chris. Many thanks

10 Mar 2011

Well, sure, mbed compiler supports C. However, it doesn't mean you can just take code from one device and expect it to work on another. There's a lot of device-specific functions being used here.

10 Mar 2011

I think that's the problem for me Igor, not being code 'savvy', I wouldn't know what to change to make the device specific functions for this code work on mbed - I really appreciate your help.

11 Mar 2011

Hi Dave,

In your program, you have two includes:

#include "ftlibc.h"
#include "ANALOGUE.h"

Are these also included in your mbed program? Also, I don't see a main(); is that in another file within your program?

Probably good to start with a high level description of what you are trying to achieve, and the building blocks you have so far. That'll help give some context to what exactly isn't working.

Simon

11 Mar 2011

Thanks Simon, I've spoken with Chris Styles today who will be able to brief you.