SunQuest
           C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 5th, 2008, 02:57 AM
wam wam is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 3 wam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 14 sec
Reputation Power: 0
Array values export problem to DLL

I have written a code for maximum power point tracking. The purpose was to create DLL file and use it in a circuit base simulation program. I used Microsoft visual c++ 2008 express and created that DLL file but I only get first value from the created array in C. I mean circuit based simulation program only get first value (although I see all array values after executing in "ChSciTE"). Do I need to store data somewhere? I am kind of rookie about writing C code...The code is below and the algorithm is attached as pdf. If anyone help me I would be so happy... I have been playing with this for 3 weeks...

Code:
#include <math.h>

    main() {

	
    static double y[21];                       //controlled variable
    static double m_A[21];              //modulation index          
    double dm_A=0.05;                   //small change for modulation index
    int n;
    double i_cell[]={4.65, 4.68, 4.7, 3.7, 2.1, 2.8,4.68, 4.65, 3.9, 3.7, 2.1, 2.8,4.68, 4.65, 3.9, 4.3, 2.1, 3.3, 4, 3.7,4.6}; 
	
        
        
        for (n=1;n<=19;n++){
        
        m_A[0]=0.75;
        m_A[1]=0.65;
            
        y[n-1]=i_cell[n-1]*m_A[n-1];                 //estimated initial controlled variable
        y[n]=i_cell[n]*m_A[n];  

    if (((m_A[n]>=m_A[n-1]) && (y[n]>=y[n-1])) ||    //algorithm for maximum power point tracking
        (((m_A[n]<m_A[n-1]) && (y[n]<y[n-1]))))	
                   
        m_A[n+1]=m_A[n]+dm_A;           //increase modulation index
                                         
    else                                //while one of them is increasing and the other one decreasing
         
        m_A[n+1]=m_A[n]-dm_A;           //decrease modulation index  
  
 
        printf("%f \n",m_A[n+1]);       //display modulation indices
            
                        }
            }   


The code above for seeing results in "ChSciTE" program but the one I pasted below creates that DLL file to use in simulation.

Code:
#include <math.h>
__declspec(dllexport) void simuser (t, delt, in, out)
double t, delt;
double *in, *out;
{


	static double y[21];				//controlled variable
	static double m_A[21];				//modulation index
	double i_cell=4.65;			       //estimated initial current value
	int n;
		
		
	for (n=1;n<=19;n++){
		m_A[0]=0.75;					//estimated initial current value
		m_A[1]=0.65;					//second estimated initial current value
	
		y[n-1]=i_cell*m_A[0];			//estimated initial controlled variable
		y[n]=in[0]*m_A[n];				//in[0] current input value which comes from simulation 					

	
	if (((m_A[n]>=m_A[n-1]) && (y[n]>=y[n-1])) || 
		(((m_A[n]<m_A[n-1]) && (y[n]<y[n-1]))))	
            
		m_A[n+1]=m_A[n]+in[1];			//in[1] which is input 2 from circuit based simulation
	
	else								//while one of them increases and the other one decreases
        m_A[n+1]=m_A[n]-in[1];			//decrease modulation index

	out[0]=m_A[n+1];					// out[0] is output which is transfered to the simulation with DLL
	
						}		
		 	

}


in[0]: first input comes from simulation program
in[1]: second input comes from simulation program
out[0]: output from C code or DLL file goes to simulation or taken by simulation program

Those values taken by simulation should be m_A[n+1]? As far as I understand which is an array. However only the first, I mean m_A[1+1] = m_A[2] has taken by simulation. How could I write the code all values from m_A[2], m_A[3]........m_A[20] can be taken by simulation or DLL sends those values to simulation program one by one for every 20 ms or different interval...

Reply With Quote
  #2  
Old May 6th, 2008, 08:27 AM
wam wam is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 3 wam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 14 sec
Reputation Power: 0
Can anyone help me about this???

Reply With Quote
  #3  
Old May 6th, 2008, 03:44 PM
LaughingBelly's Avatar
LaughingBelly LaughingBelly is offline
Who set my Title?
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2004
Posts: 526 LaughingBelly User rank is First Lieutenant (10000 - 20000 Reputation Level)LaughingBelly User rank is First Lieutenant (10000 - 20000 Reputation Level)LaughingBelly User rank is First Lieutenant (10000 - 20000 Reputation Level)LaughingBelly User rank is First Lieutenant (10000 - 20000 Reputation Level)LaughingBelly User rank is First Lieutenant (10000 - 20000 Reputation Level)LaughingBelly User rank is First Lieutenant (10000 - 20000 Reputation Level)LaughingBelly User rank is First Lieutenant (10000 - 20000 Reputation Level)LaughingBelly User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 23 h 26 sec
Reputation Power: 204
Welcome to DevShed. The reason why you have not received a response is that your question is not clear and is missing details.

To me it looks like you are trying to bite more than you can chew. You need to first understand how dlls work and how static variables work.

Where are you calling the exported function simuser? Why do you think the static array m_A should be shared between a function in the dll and the main function somewhere else? what have you done to make sure they are sync'd? Show us that part of code and we might be able to shine some light on why it is not working for you.
__________________
Nobody is perfect. I am Nobody.

Reply With Quote
  #4  
Old May 6th, 2008, 09:02 PM
wam wam is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 3 wam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 14 sec
Reputation Power: 0
Quote:
Originally Posted by LaughingBelly
Welcome to DevShed. The reason why you have not received a response is that your question is not clear and is missing details.

To me it looks like you are trying to bite more than you can chew. You need to first understand how dlls work and how static variables work.

Where are you calling the exported function simuser? Why do you think the static array m_A should be shared between a function in the dll and the main function somewhere else? what have you done to make sure they are sync'd? Show us that part of code and we might be able to shine some light on why it is not working for you.


You are right I do not know how DLLs work. I only know when you create DLL file you can use it in another application.

Actually Fucntion Simuser it is not a real function, it is a circuit based simulation tool "PSIM" (power electronics simulation tool). It has an ability to include DLL files for control purposes.

If you google "PSIM DLL" you will find a document which is "PSIM SIMULATION SOFTWARE TUTORIAL How to use the DLL Block"

Why they are static double, again I don't really know. I have seen someone used variable like that in this kind of application.

Firstly I wrote down a code in C and I got array's 20 output (You can imagine that from the first program). Then I wrote same code (I thought it is the same) to create DLL file to send those array values to that simulation program. However simulation program only obtain the first value which sent by DLL.

I agree I need to understand more and programming quite interesting. I can not imagine things due to lack of knowledge.

Thank you very much for answering me In this stage is it possible to suggest me something?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Array values export problem to DLL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway