/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / mems sensor

Username:     
Password:     
             

Forum

# 1   2009-04-20 16:59:55 mems sensor

Artic
New member
Registered: 2009-02-19
Posts: 5

mems sensor

good afternoon, right now I am trying to understand how the Mems sensor work. I am trying to get this to work without using circleOS.

I have defined this on my main application:

typedef struct
{
   s16 OutX ;
   s16 OutX_F4 ;
   s16 OutX_F16 ;
   s32 OutX_F64 ;
   s32 OutX_F256 ;
   s16 OutY ;
   s16 OutY_F4 ;
   s16 OutY_F16 ;
   s32 OutY_F64 ;
   s32 OutY_F256 ;
   s16 OutZ ;
   s16 OutZ_F4 ;
   s16 OutZ_F16 ;
   s32 OutZ_F64 ;
   s32 OutZ_F256 ;
   s16 Shocked ;
   s16 RELATIVE_X ;
   s16 RELATIVE_Y ;
   s16 DoubleClick ;
}tMEMS_Info;

taken from mems.c

The objective of the program is just to move a box according to the information read from the sensor.

right now it looks like this:

int main(void)
{
   int x=0;
   tMEMS_Info sensor;
   s16 Current_MEMS_Y, Initial_MEMS_Y, delta;
   LCD_Init();
   MEMS_Init();
   MEMS_GetInfo();
   LCD_FillRect(0,0,132,132,0xffff);
   LCD_FillRect(61,61,10,10,0x0000);
   for( ; ; )
   {
      MEMS_GetInfo();
      Current_MEMS_Y = sensor.OutY_F4;
      delta = Current_MEMS_Y - Initial_MEMS_Y;
      x = (delta + 3000) / 2000;
     
      LCD_FillRect(0,0,132,132,0xffff);
      LCD_FillRect(61,x,10,10,0x0000);   
      Initial_MEMS_Y = Current_MEMS_Y;
   }
}


This code does nothing. It draws a box on the center and then it moves to the bottom of the screen and nothing else. No matter how i move the primer the box does not move.
I am doing something very wrong but cannot spot it.

I would be gratefull if anyone could help me. Thanks in advance

Offline

 

# 2   2009-04-21 07:28:07 mems sensor

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: mems sensor

First of all,  check in MEMS_Init if you read the id code of the MEMS (i.e. if the MEMS is properly initialized). The, check of your structure is changed when you move your Primer...
All this can be done in debug mode.

Offline

 

# 3   2009-04-21 10:20:45 mems sensor

Artic
New member
Registered: 2009-02-19
Posts: 5

Re: mems sensor

Thanks for your answer. I've done the Mems_Init step by step and It jumps to the MEMS_ReadID. Everything looks fine.

Offline

 

# 4   2009-04-21 11:44:43 mems sensor

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: mems sensor

Ok...
The explanation: MEMS_GetInfo() returns the structure read by the MEMS_Handler. But if you are out of CircleOS, you don't call the MEMS_Handler function.

Offline

 

# 5   2009-04-21 15:32:21 mems sensor

Artic
New member
Registered: 2009-02-19
Posts: 5

Re: mems sensor

thanks for your help. will try to look at that today. I need to call that MEMS_Handler before calling MEMS_GetInfo right?

Offline

 

# 6   2009-04-21 16:50:27 mems sensor

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: mems sensor

Yes, MEMS_Handler calls MEMS_ReadOutXY that updates the structure that is read by MEMS_GetInfo.
MEMS_Handler is supposed to be called at a fixed frequency.
In your case, calling MEMS_ReadOutXY could be sufficent.

Offline

 

Board footer