Ok I have discarded the frequency meter and I have made a little modification to the sample Signal_replicaā¦
/********************************************************************************************/
/* signal_replica.c - Copyright Wavecom S.A. (c) 2002 */
/* */
/* */
/* DISCLAIMER OF WARRANTY */
/* ====================== */
/* This Software is provided free of charge on an 'as is' basis. No warranty is given */
/* by Wavecom S.A. in relation to the Software of the uses to which it may be put by you, */
/* the user, or its merchantability, fitness or suitability for any particular purpose */
/* or conditions; and/or that the use of the Software and all documentation relating */
/* thereto by the Licensee will not infringe any third party copyright or other */
/* intellectual property rights. Wavecom S.A. shall furthermore be under no obligation */
/* to provide support of any nature for the Software and the Documentation. */
/* */
/* LIMIT OF LIABILITY */
/* ================== */
/* In no event shall Wavecom S.A. be liable for any loss or damages whatsoever or howsoever */
/* caused arising directly or indirectly in connection with this licence, the Software, */
/* its use or otherwise except to the extent that such liability may not be lawfully */
/* excluded. Notwithstanding the generality of the foregoing, Wavecom S.A. expressly */
/* excludes liability for indirect, special, incidental or consequential loss or damage */
/* which may arise in respect of the Software or its use, or in respect of other equipment */
/* or property, or for loss of profit, business, revenue, goodwill or anticipated savings. */
/* */
/********************************************************************************************/
/***************************************************************************/
/* File : signal_replica.c */
/*-------------------------------------------------------------------------*/
/* Object : Customer application */
/* */
/* contents : Customer main procedures */
/* */
/* Change : */
/***************************************************************************/
/*
$LogWavecom: G:\projet\mmi\pvcsarch\archives\open-mmi\SAMPLES\adl\New_Project\src\appli.c-arc $
* --------------------------------------------------------------------------
* Date | Author | Revision | Description
* ----------+--------+----------------+-------------------------------------
* 25.10.05 | DPO | 1.1 | * New V4 interface
* ----------+--------+----------------+-------------------------------------
* 16.12.02 | dpo | 1.0 | Initial revision.
* ----------+--------+----------------+-------------------------------------
*/
#include "adl_global.h"
/***************************************************************************/
/* Mandatory variables */
/*-------------------------------------------------------------------------*/
/* wm_apmCustomStackSize */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
const u16 wm_apmCustomStackSize = 1024*3;
const u32 wm_apmIRQLowLevelStackSize = 1024;
const u32 wm_apmIRQHighLevelStackSize = 1024;
/***************************************************************************/
/* Local variables */
/***************************************************************************/
// GPIO output to use
#define OUTPUT_GPIO_LABEL ( ADL_IO_GPIO | 0 )
// Commands strings
static const ascii * AtCmdStr_SIGNAL = "AT+SIGNAL";
// Interruption handle
static s32 MyIrqHandle;
// ExtInt service handle
static s32 MyExtIntHandle = ERROR;
// GPIO service handle
static s32 MyGpioHandle = ERROR;
// Signal generation mode
static bool signal_Mode;
// Signal output GPIO ID
static u8 signal_OutputIo = 1;
static u8 signal_OutputIoInnerID;
// Signal input pin
static adl_extintID_e signal_InputPin;
// Signal input filter
static adl_extintFilter_e signal_Filter;
// ExtInt Capabilities
static adl_extintCapabilities_t irq_ExtIntCapabilities;
// Signal debounce duration
static u8 signal_DebounceDuration = 1;
// ExtInt settings
adl_extintConfig_t signal_inputSettings;
/***************************************************************************/
/* Local functions */
/***************************************************************************/
/****************************************************************************/
/* Function : MyIrqHandler */
/*--------------------------------------------------------------------------*/
/* Scope : ADL Interruption service low level handler */
/* */
/* Return : TRUE to enable High level handler notification */
/* FALSE to disable High level handler notification */
/* */
/*--------------------+---+---+---------------------------------------------*/
/* Variable Name |IN |OUT| Use */
/*--------------------+---+---+---------------------------------------------*/
/* Source | X | | Interruption source identifier */
/*--------------------+---+---+---------------------------------------------*/
/* NotificationLevel | X | | Handler notification level */
/*--------------------+---+---+---------------------------------------------*/
/* Data | X | X | Interruption event data structure */
/*--------------------+---+---+---------------------------------------------*/
/****************************************************************************/
int counter=0;
static bool MyIrqHandler ( adl_irqID_e Source, adl_irqNotificationLevel_e NotificationLevel, adl_irqEventData_t * Data )
{
s32 sReturn;
adl_ioDefs_t Gpio_to_write = ADL_IO_GPIO | signal_OutputIoInnerID ;
// WARNING: low level execution context
TRACE (( 2, "IRQ interruption handler (Input: %d)", ( ( adl_extintInfo_t * ) Data->SourceData )->PinState ));
// Check interruption edge
if ( signal_inputSettings.Sensitivity == ADL_EXTINT_SENSITIVITY_RISING_EDGE )
{
// Rising edge: set output to 1
sReturn = adl_ioWriteSingle ( MyGpioHandle, &Gpio_to_write, TRUE );
counter++;
// Reverse polarity
signal_inputSettings.Sensitivity = ADL_EXTINT_SENSITIVITY_FALLING_EDGE;
}
else
{
// Falling edge: set output to 0
sReturn = adl_ioWriteSingle ( MyGpioHandle, &Gpio_to_write, FALSE );
// Reverse polarity
signal_inputSettings.Sensitivity = ADL_EXTINT_SENSITIVITY_RISING_EDGE;
}
if ( sReturn < 0 )
TRACE (( 2, "adl_ioWriteSingle GPIO %d : %d error %X ",signal_OutputIoInnerID, sReturn , Gpio_to_write & ADL_IO_ERR_MSK ));
// Re-configure to reverse polarity
adl_extintConfig ( MyExtIntHandle, &signal_inputSettings );
return FALSE;
}
void my_function(u8 ID, void * Context){
ascii *myMsg;
myMsg = adl_memGet(sizeof(ascii)*128); // allocate memory for string
myMsg[0] = 0x00; // ensure string starts with 'NUL'
wm_sprintf(myMsg, "Value of Counter is %d", counter);
adl_atSendResponse(ADL_AT_RSP, myMsg);
adl_memRelease(myMsg);
counter=0;
}
/****************************************************************************/
/* Function : MyControlCommandHandler */
/*--------------------------------------------------------------------------*/
/* Scope : AT+SIGNAL command handler */
/* */
/* Return : VOID */
/* */
/*--------------------+---+---+---------------------------------------------*/
/* Variable Name |IN |OUT| Use */
/*--------------------+---+---+---------------------------------------------*/
/* params | X | | Incoming AT command parameters */
/*--------------------+---+---+---------------------------------------------*/
/****************************************************************************/
static void MyControlCommandHandler ( adl_atCmdPreParser_t * params )
{
ascii RspStr [ 80 ];
// Switch on command type
switch ( params->Type )
{
// Test command
case ADL_CMD_TYPE_TEST :
wm_sprintf ( RspStr, "\r\n%s: (0-1),(0-%d),(0-%d),(0-%d),(0-%d)\r\n", AtCmdStr_SIGNAL + 2, ADL_IO_NUM_MSK, irq_ExtIntCapabilities.NbExternalInterrupt - 1, irq_ExtIntCapabilities.DebounceMode , irq_ExtIntCapabilities.MaxDebounceDuration - 1);
adl_atSendResponsePort ( ADL_AT_RSP, params->Port, RspStr );
adl_atSendStdResponsePort ( ADL_AT_RSP, params->Port, ADL_STR_OK );
break;
// Read command
case ADL_CMD_TYPE_READ :
wm_sprintf ( RspStr, "\r\n%s: %d,%d,%d,%d,%d\r\n", AtCmdStr_SIGNAL + 2, signal_Mode, signal_OutputIo, signal_InputPin, signal_Filter, signal_DebounceDuration );
adl_atSendResponsePort ( ADL_AT_RSP, params->Port, RspStr );
adl_atSendStdResponsePort ( ADL_AT_RSP, params->Port, ADL_STR_OK );
break;
// Parameters command
case ADL_CMD_TYPE_PARA :
{
// Analyses parameters
ascii * P0 = ADL_GET_PARAM ( params, 0 ),
* P1 = ADL_GET_PARAM ( params, 1 ),
* P2 = ADL_GET_PARAM ( params, 2 ),
* P3 = ADL_GET_PARAM ( params, 3 ),
* P4 = ADL_GET_PARAM ( params, 4 );
u8 iP0, iP1;
s32 sReturn;
// Check Parameters
if ( !P0
// Mode
|| ( ( iP0 = wm_atoi ( P0 ) ) > 1 )
// Output IO ID
|| ( P1
&& ( ( ( iP1 = wm_atoi ( P1 ) ) < 1 )
|| ( iP1 > ADL_IO_NUM_MSK)
)
)
)
{
// Syntax error
adl_atSendStdResponseExtPort ( ADL_AT_RSP, params->Port, ADL_STR_CME_ERROR, 3 );
}
else
{
// Check if signal is running
if ( signal_Mode )
{
// Unsubscribe from ExtInt service
sReturn = adl_extintUnsubscribe ( MyExtIntHandle );
MyExtIntHandle = ERROR;
TRACE (( 1, "Unsubscribe from ExtInt: %d", sReturn ));
// Unsubscribe from GPIO
sReturn = adl_ioUnsubscribe ( MyGpioHandle );
MyGpioHandle = ERROR;
TRACE (( 1, "Unsubscribe from GPIO %d: %d", signal_OutputIo, sReturn ));
}
// Update signal mode
signal_Mode = iP0;
TRACE (( 1, "New signal mode: %d", signal_Mode ));
// Check for mode
if ( signal_Mode )
{
// GPIO 0 by default
adl_ioDefs_t GpioConfig = OUTPUT_GPIO_LABEL | ADL_IO_DIR_OUT | ADL_IO_LEV_LOW ;
// Set input pin (if supplied)
if ( P2 )
{
signal_InputPin = wm_atoi ( P2 );
}
// Set input process (if supplied)
if ( P3 )
{
signal_Filter = wm_atoi ( P3 );
}
// Set debounce duration (if supplied)
if ( P4 )
{
signal_DebounceDuration = wm_atoi ( P4 );
}
// Fill IO settings, according to desired value (if supplied)
if ( P1 )
{
signal_OutputIoInnerID = iP1;
}
GpioConfig = GpioConfig | signal_OutputIoInnerID ;
TRACE (( 1, "GPIO ID for current product: %d", signal_OutputIoInnerID ));
// Subscribe IO
MyGpioHandle = adl_ioSubscribe ( 1, &GpioConfig, 0, 0, 0 );
TRACE (( 1, "Subscribe to GPIO: %d", MyGpioHandle ));
// Check if subscription is OK
if ( MyGpioHandle >= 0 )
{
// Remember GPIO id
signal_OutputIo = iP1;
// Fill ExtInt settings, according to the supplied ones
signal_inputSettings.Sensitivity = ADL_EXTINT_SENSITIVITY_RISING_EDGE;
signal_inputSettings.Filter = signal_Filter;
signal_inputSettings.FilterDuration = signal_DebounceDuration;
TRACE (( 1, "Input process %d; debounce duration %d", signal_Filter, signal_DebounceDuration ));
// Subscribe to the ExtInt service
MyExtIntHandle = adl_extintSubscribe ( signal_InputPin, MyIrqHandle, 0, &signal_inputSettings );
TRACE (( 1, "Subscribe to ExtInt (%d): %d", signal_InputPin, MyExtIntHandle ));
// Check if subscription is OK
if ( MyExtIntHandle >= 0 )
{
// OK...
adl_atSendStdResponsePort ( ADL_AT_RSP, params->Port, ADL_STR_OK );
}
else
{
// Reset state
signal_Mode = FALSE;
// ExtInt Subscription error
adl_atSendStdResponseExtPort ( ADL_AT_RSP, params->Port, ADL_STR_CME_ERROR, 3 );
}
}
else
{
// Reset state
signal_Mode = FALSE;
// GPIO Subscription error
adl_atSendStdResponseExtPort ( ADL_AT_RSP, params->Port, ADL_STR_CME_ERROR, 3 );
}
}
else
{
// Nothing to do
adl_atSendStdResponsePort ( ADL_AT_RSP, params->Port, ADL_STR_OK );
}
}
}
break;
}
}
/***************************************************************************/
/* Function : adl_main */
/*-------------------------------------------------------------------------*/
/* Object : Customer application initialisation */
/* */
/*-------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+----------------------------------------*/
/* InitType | | | | Application start mode reason */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void adl_main ( adl_InitType_e InitType )
{
TRACE (( 1, "Signal Replica Sample: Main" ));
// Interruption & message handlers definition
MyIrqHandle = adl_irqSubscribe ( MyIrqHandler, ADL_IRQ_NOTIFY_LOW_LEVEL, ADL_IRQ_PRIORITY_HIGH_LEVEL, ADL_IRQ_OPTION_AUTO_READ );
TRACE (( 1, "Interruption handler subscription: %d", MyIrqHandle ));
TRACE (( 1, "Application context diagnostic: %X", adl_ctxGetDiagnostic() ));
// Get ExtInt Capabilties
adl_extintGetCapabilities( &irq_ExtIntCapabilities );
// Subscribe to start/stop command if all is OK for IRQ subscription
if ( MyIrqHandle >= OK )
{
// Subscribe to the control command
adl_atCmdSubscribe ( AtCmdStr_SIGNAL, MyControlCommandHandler, ADL_CMD_TYPE_TEST | ADL_CMD_TYPE_READ | ADL_CMD_TYPE_PARA | 0x51 );
}
else if ( MyIrqHandle == ADL_RET_ERR_NOT_SUPPORTED )
{
// Feature not enabled
adl_atSendResponse ( ADL_AT_UNS, "\r\nInit Failed; Real Time enhancement feature not enabled.\r\n" );
}
adl_tmrSubscribe ( TRUE, 600, ADL_TMR_TYPE_100MS, my_function );
}
The program works fine when I give an input signal of 2.7 V pp and 0.25 Hz or less but If I give a higher frecuency (for example 0.5 Hz, 1Hz, etc) it doesnt copy the squared waveā¦why???
I thought it could handle waves of 500 Hz!!! I have tried to activate manually the interruptions with the following commandā¦
āAT+WIPC=1,āINT1ā,0,0ā and after that I run the application but it still behaves like beforeā¦I have also reseted the modem wit āAT+CFUN=1āā¦but nothing happensā¦
Should I probe another commands?
Does anyone know how could I activate the INTERRUPTIONS?