aversive_10-03-12/modules/devices/encoders/encoders_microb/encoders_microb.c File Reference

Implementation for getting motor position. More...

#include <stdlib.h>
#include <aversive.h>
#include <aversive/wait.h>
#include <encoders_microb.h>
#include <encoders_microb_config.h>

Go to the source code of this file.

Defines

#define SEL_A()   cbi(ENCODERS_MICROB_SEL_PORT,ENCODERS_MICROB_SEL_BIT)
#define SEL_B()   sbi(ENCODERS_MICROB_SEL_PORT,ENCODERS_MICROB_SEL_BIT)
#define READ(n)
#define INIT(n)

Functions

void encoders_microb_init (void)
void encoders_microb_manage (void *dummy)
int32_t encoders_microb_get_value (void *number)
void encoders_microb_set_value (void *number, int32_t v)

Variables

int32_t g_encoders_microb_values [ENCODERS_MICROB_NUMBER]
int8_t g_encoders_microb_previous [ENCODERS_MICROB_NUMBER]


Detailed Description

Implementation for getting motor position.

Todo:
test the module
Test:
nothing done
This module provides functions for getting position from coders. Its implementation depends on hardware, so that's why there is (or will be) multiple implementation of this module.

The harware is quite simple here :

 * ----------
 * |        |  8
 * |    PINx|<-/---  value
 * |        |   
 * |        |  8
 * |    PINy|<-/---  value
 * |        |
 * |        |  8
 * |    PINz|<-/---  value
 * |        |
 * |    ....|
 * |        |
 * |    SEL |---->  (1 bit)
 * |        |  
 * |        |
 * |        |
 * ----------
 * 

Definition in file encoders_microb.c.


Define Documentation

#define INIT (  ) 

Value:

do {                              \
g_encoders_microb_values[n] = 0;                    \
} while(0)

Definition at line 91 of file encoders_microb.c.

Referenced by encoders_microb_init().

#define READ (  ) 

Value:

do {                                                \
val = ENCODERS_MICROB##n##_PIN;                     \
nop();                                              \
if (val != ENCODERS_MICROB##n##_PIN)                \
     val = ENCODERS_MICROB##n##_PIN;                \
                                                    \
res = (val - g_encoders_microb_previous[n]);        \
g_encoders_microb_previous[n] = val;                \
                                                    \
g_encoders_microb_values[n] += (int32_t)res ;           \
} while(0)

Definition at line 76 of file encoders_microb.c.

Referenced by encoders_microb_manage().

 
#define SEL_A (  )     cbi(ENCODERS_MICROB_SEL_PORT,ENCODERS_MICROB_SEL_BIT)

Definition at line 71 of file encoders_microb.c.

Referenced by encoders_microb_init(), and encoders_microb_manage().

 
#define SEL_B (  )     sbi(ENCODERS_MICROB_SEL_PORT,ENCODERS_MICROB_SEL_BIT)

Definition at line 72 of file encoders_microb.c.

Referenced by encoders_microb_init(), and encoders_microb_manage().


Function Documentation

int32_t encoders_microb_get_value ( void *  number  ) 

Extract encoder value.

Parameters:
number : a (void *) that is casted in (int) containing the number of the encoder to be read.

Definition at line 230 of file encoders_microb.c.

References g_encoders_microb_values, IRQ_LOCK, and IRQ_UNLOCK.

void encoders_microb_init ( void   ) 

Initialisation of encoders, variables

Definition at line 104 of file encoders_microb.c.

References DDR, encoders_microb_manage(), INIT, IRQ_LOCK, IRQ_UNLOCK, sbi, SEL_A, SEL_B, and wait_4cyc.

void encoders_microb_manage ( void *  dummy  ) 

Update encoders values, need to be done quite often (Fmax_encoders/64). First, encoders 0 2 4 6 are read, and at next call encoders 1 3 5 7.

Parameters:
dummy : a (void *) pointer that is not used. It is here according to the encoders interface.

Definition at line 166 of file encoders_microb.c.

References IRQ_LOCK, IRQ_UNLOCK, READ, SEL_A, and SEL_B.

Referenced by encoders_microb_init().

void encoders_microb_set_value ( void *  number,
int32_t  v 
)

Set an encoder value

Parameters:
number : a (void *) that is casted in (int) containing the number of the encoder to be read.
v : the value

Definition at line 248 of file encoders_microb.c.

References g_encoders_microb_values, IRQ_LOCK, and IRQ_UNLOCK.


Variable Documentation

int8_t g_encoders_microb_previous[ENCODERS_MICROB_NUMBER]

Definition at line 67 of file encoders_microb.c.

int32_t g_encoders_microb_values[ENCODERS_MICROB_NUMBER]

Definition at line 66 of file encoders_microb.c.

Referenced by encoders_microb_get_value(), and encoders_microb_set_value().


Generated on Fri Mar 12 06:32:06 2010 for AVR by  doxygen 1.5.6