Hi,
Well in my application I would like to have ANT channel period at 20Hz. With that I would ideally want the time sync clock to work at 1 Khz. Based on the examples codes available in the application I cannot get this to work on the nrf52 development board. What i get working it that ant frequency should be twice the time sync clock. Based on my understanding there should be no such limitation as RTC 2 is just a counter and say every 1 ms it triggers a toggle on GPIO. The Ant time sync would just match the phase of the two trigger events and the ANT channel period determined how often do we want to correct the counter's trigger.
What I do is use a scope on transmitter and receiver and check the gpio toggle frequency. without the Ant both triggers work fine even at 1Khz but with the ant time sync on the receiver i see that the trigger stops (that is on the scope i get a fixed high or low) this is when ever we correct counter with ANT. Now in some cases this pause is temporary but in some cases this is permanent and i have to reset the receiver and turn the transmitter off to get the response..
Currently this is the only ANT event that I have.
Here is the main code on the receiver's side
void ant_evt_dispatch(ant_evt_t * p_ant_evt)
{
ANT_MESSAGE * pstEventMessage = (ANT_MESSAGE *) p_ant_evt;
if ((pstEventMessage->ANT_MESSAGE_ucMesgID == MESG_BROADCAST_DATA_ID) // Check if this is a broadcast message
&& (pstEventMessage->ANT_MESSAGE_aucPayload[0] == TIME_SYNC_PAGE)) // Check if this is the time synchronization page
{
//nrf_drv_rtc_disable(&m_rtc);
// Get 4-byte RTC1 time stamp from extended data
time_stamp = (pstEventMessage->ANT_MESSAGE_aucExtData[2] << 16) +
(pstEventMessage->ANT_MESSAGE_aucExtData[1] << 8) +
pstEventMessage->ANT_MESSAGE_aucExtData[0];
//pstEventMessage->ANT_MESSAGE_aucExtData[3] << 24) +
// Get time sync offset from time sync packet
offset = (pstEventMessage->ANT_MESSAGE_aucPayload[7] << 8) +
pstEventMessage->ANT_MESSAGE_aucPayload[6];
// Calculate the next event time
comp_chann_val = time_stamp - offset + LED_INVERT_PERIOD;
// Setup RTC to fire during the next period
nrf_drv_rtc_cc_set(&m_rtc, ANT_RTC_CHANNEL, comp_chann_val, true);
//nrf_drv_rtc_enable(&m_rtc);
}
}
static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
{
if (int_type == NRF_DRV_RTC_INT_COMPARE0)
{
nrf_gpio_pin_toggle(17);
// Get the current RTC counter value
uint32_t count = nrf_drv_rtc_counter_get(&m_rtc);
// Set the RTC channel to interrupt again after the LED_INVERT_PERIOD
ret_code_t err_code = nrf_drv_rtc_cc_set(&m_rtc,
ANT_RTC_CHANNEL,
count + LED_INVERT_PERIOD,
true);
}
}
static void ant_channel_rx_broadcast_setup(void)
{
uint32_t err_code;
ANT_TIME_STAMP_CONFIG stampConfig;
// Configure ANT Channel
ant_channel_config_t broadcast_channel_config =
{
.channel_number = ANT_BROADCAST_CHANNEL_NUMBER,
.channel_type = CHANNEL_TYPE_SLAVE,
.ext_assign = EXT_ASSIGN_NONE,
.rf_freq = RF_FREQ,
.transmission_type = CHAN_ID_TRANS_TYPE,
.device_type = CHAN_ID_DEV_TYPE,
.device_number = CHAN_ID_DEV_NUM,
.channel_period = CHAN_PERIOD,
.network_number = ANT_NETWORK_NUMBER,
};
// Configure received message timestamp to use RTC1 (4 byte counter)
stampConfig.ucTimeBase = ANT_TIME_BASE_ALT2;
stampConfig.bTimeStampEnabled = true;
err_code = sd_ant_time_stamp_config_set(&stampConfig;);
APP_ERROR_CHECK(err_code);
// Initialize channel configuration
err_code = ant_channel_init(&broadcast;_channel_config);
APP_ERROR_CHECK(err_code);
// Disable high priority search timeout and set the proper channel number
ant_search_config_t ant_search_config = DEFAULT_ANT_SEARCH_CONFIG(ANT_BROADCAST_CHANNEL_NUMBER);
ant_search_config.high_priority_timeout = ANT_HIGH_PRIORITY_TIMEOUT_DISABLE;
// Set search timeout
err_code = ant_search_init(&ant;_search_config);
APP_ERROR_CHECK(err_code);
// Open channel.
err_code = sd_ant_channel_open(ANT_BROADCAST_CHANNEL_NUMBER);
APP_ERROR_CHECK(err_code);
}
static void rtc_config(void)
{
uint32_t err_code;
// Initialize RTC instance
nrf_drv_rtc_config_t config = NRF_DRV_RTC_DEFAULT_CONFIG;
err_code = nrf_drv_rtc_init(&m_rtc, &config;, rtc_handler);
APP_ERROR_CHECK(err_code);
// Enable tick event & interrupt
nrf_drv_rtc_tick_enable(&m_rtc, true);
// Set compare channel to trigger interrupt after LED_INVERT_PERIOD
err_code = nrf_drv_rtc_cc_set(&m_rtc, ANT_RTC_CHANNEL, LED_INVERT_PERIOD, true);
APP_ERROR_CHECK(err_code);
// Power on RTC instance
nrf_drv_rtc_enable(&m_rtc);
}
This is the code for Transmitter's side
void ant_time_sync_message_send()
{
uint32_t err_code;
uint8_t message_payload[ANT_STANDARD_DATA_PAYLOAD_SIZE];
uint32_t counter;
// Get the current RTC counter value
counter = nrf_drv_rtc_counter_get(&m_rtc);
nrf_drv_rtc_cc_set(&m_rtc, ANT_RTC_CHANNEL, counter + LED_INVERT_PERIOD, true);
// Assign a new value to the broadcast data.
memset(message_payload, 0, ANT_STANDARD_DATA_PAYLOAD_SIZE);
message_payload[0] = TIME_SYNC_PAGE;
message_payload[4] = 0;
message_payload[5] = 0;
message_payload[6] = (uint8_t) LSB_32(counter); // 2-byte counter LSB
message_payload[7] = (uint8_t) LSB_32(counter >> 8); // 2-byte counter MSB
// Broadcast the data.
err_code = sd_ant_time_sync_broadcast_tx(ANT_BROADCAST_CHANNEL_NUMBER,