Part Number: TMS320F28379D
Tool/software: Code Composer Studio
I am transmitting data over CAN I need to to send two frame with 0.5 cycle time.
But there is difference in cycle time b/w two frame can You guide me this is my code.
#include "driverlib.h"
#include "device.h"
#include "pin_map.h"
//
// Defines
//
#define TXCOUNT 100000
#define MSG_DATA_LENGTH 8
#define TX_MSG_OBJ_ID 1
//
// Globals
//
volatile unsigned long i;
volatile uint32_t txMsgCount = 0;
uint16_t txMsgData[8];
uint16_t WSS_Data[8];
float Pressure_Sensor1,Pressure_Sensor2;
int POF1,POF2;
//
// Included Files
//
//
// Defines
//
#define RESULTS_BUFFER_SIZE 256
#define EX_ADC_RESOLUTION 12
//
// Globals
//
uint16_t adcAResult0;
uint16_t adcAResult1;
uint16_t adcBResult0;
uint16_t adcBResult1;
//
// Function Prototypes
//
void initADCs(void);
void initADCSOCs(void);
//
// Main
//
void main(void)
{
Device_init();
//
// Initialize GPIO and configure GPIO pins for CANTX/CANRX
// on module A
//
Device_initGPIO();
GPIO_setPinConfig(0x00080202U);
GPIO_setPinConfig(0x00061802U);
//
// Initialize the CAN controllers
//
CAN_initModule(CANB_BASE);
//
// Set up the CAN bus bit rate to 500kHz for each module
// Refer to the Driver Library User Guide for information on how to set
// tighter timing control. Additionally, consult the device data sheet
// for more information about the CAN module clocking.
//
CAN_setBitRate(CANB_BASE, DEVICE_SYSCLK_FREQ,500000, 10);
//
// Initialize the transmit message object used for sending CAN messages.
// Message Object Parameters:
// CAN Module: A
// Message Object ID Number: 1
// Message Identifier: 0x95555555
// Message Frame: Extended
// Message Type: Transmit
// Message ID Mask: 0x0
// Message Object Flags: None
// Message Data Length: 4 Bytes
/*Wheel speed Sensor*/
//
//
// Start CAN module A operations
//
CAN_startModule(CANB_BASE);
//
// Initialize device clock and peripherals
//
Device_init();
//
// Disable pin locks and enable internal pullups.
//
Device_initGPIO();
//
// Initialize PIE and clear PIE registers. Disables CPU interrupts.
//
Interrupt_initModule();
//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
//
Interrupt_initVectorTable();
//
// Set up ADCs, initializing the SOCs to be triggered by software
//
initADCs();
initADCSOCs();
//
// Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
//
EINT;
ERTM;
//
// Loop indefinitely
//
while(1)
{
//
// Convert, wait for completion, and store results
//
ADC_forceSOC(ADCA_BASE, ADC_SOC_NUMBER0);
ADC_forceSOC(ADCA_BASE, ADC_SOC_NUMBER1);
ADC_forceSOC(ADCB_BASE, ADC_SOC_NUMBER0);
ADC_forceSOC(ADCB_BASE, ADC_SOC_NUMBER1);
//
// Wait for ADCA to complete, then acknowledge flag
//
while(ADC_getInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1) == false)
{
}
ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);
//
// Wait for ADCB to complete, then acknowledge flag
//
while(ADC_getInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1) == false)
{
}
ADC_clearInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1);
//
// Store results
//
adcAResult0 = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER0);
adcAResult1 = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER1);
adcBResult0 = ADC_readResult(ADCBRESULT_BASE, ADC_SOC_NUMBER0);
adcBResult1 = ADC_readResult(ADCBRESULT_BASE, ADC_SOC_NUMBER1);
float conv = (3.3)/(4096*0.6);
if((adcAResult0 * conv)>=0.5){
POF1 = 1;
}
else{
POF1 = 0;
}
if((adcAResult1 * conv)>=0.5){
POF2 = 1;
}
else{
POF2 = 0;
}
Pressure_Sensor1 = POF1*((adcAResult0 * conv)-0.5)*43.48;
Pressure_Sensor2 = POF2*((adcAResult1 * conv)-0.5)*43.48;
/**************************************/
CAN_setupMessageObject(CANB_BASE,1, 0x00A,
CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_TX, 0,
CAN_MSG_OBJ_NO_FLAGS, MSG_DATA_LENGTH);
WSS_Data[0] = 0xFF; //Wheel speed
WSS_Data[1] = 0xFF;
WSS_Data[2] = 0xFF;
WSS_Data[3] = 0xFF;
WSS_Data[4] = 0xFF;
WSS_Data[5] = 0xFF;
WSS_Data[6] = 0xAF;
WSS_Data[7] = 0xFF;
CAN_sendMessage(CANB_BASE, 1, MSG_DATA_LENGTH, WSS_Data);
//*********************************************************************************************/
txMsgData[0] = (adcAResult0 >> 8) & 0x0F;
txMsgData[1] = (adcAResult0 >> 0) & 0xFF;
txMsgData[2] = (adcAResult1 >> 8) & 0x0F;
txMsgData[3] = (adcAResult1 >> 0) & 0xFF;
txMsgData[4] = 0x00;
txMsgData[5] = 0x00;
txMsgData[6] = 0x00;
txMsgData[7] = 0x00;
/*Pressure Sensor*/
CAN_setupMessageObject(CANB_BASE, TX_MSG_OBJ_ID, 0x00B,
CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_TX, 0,
CAN_MSG_OBJ_NO_FLAGS, MSG_DATA_LENGTH);
CAN_sendMessage(CANB_BASE, TX_MSG_OBJ_ID, MSG_DATA_LENGTH, WSS_Data);
//
// Software breakpoint. At this point, conversion results are stored in
// adcAResult0, adcAResult1, adcBResult0, and adcBResult1.
//
// Hit run again to get updated conversions.
//
// ESTOP0;
}
}
//
// Function to configure and power up ADCs A and B.
//
void initADCs(void)
{
//
// Set ADCCLK divider to /4
//
ADC_setPrescaler(ADCA_BASE, ADC_CLK_DIV_4_0);
ADC_setPrescaler(ADCB_BASE, ADC_CLK_DIV_4_0);
//
// Set resolution and signal mode (see #defines above) and load
// corresponding trims.
//
#if(EX_ADC_RESOLUTION == 12)
ADC_setMode(ADCA_BASE, ADC_RESOLUTION_12BIT, ADC_MODE_SINGLE_ENDED);
ADC_setMode(ADCB_BASE, ADC_RESOLUTION_12BIT, ADC_MODE_SINGLE_ENDED);
#elif(EX_ADC_RESOLUTION == 16)
ADC_setMode(ADCA_BASE, ADC_RESOLUTION_16BIT, ADC_MODE_DIFFERENTIAL);
ADC_setMode(ADCB_BASE, ADC_RESOLUTION_16BIT, ADC_MODE_DIFFERENTIAL);
#endif
//
// Set pulse positions to late
//
ADC_setInterruptPulseMode(ADCA_BASE, ADC_PULSE_END_OF_CONV);
ADC_setInterruptPulseMode(ADCB_BASE, ADC_PULSE_END_OF_CONV);
//
// Power up the ADCs and then delay for 1 ms
//
ADC_enableConverter(ADCA_BASE);
ADC_enableConverter(ADCB_BASE);
DEVICE_DELAY_US(1000);
}
//
// Function to configure SOCs 0 and 1 of ADCs A and B.
//
void initADCSOCs(void)
{
//
// Configure SOCs of ADCA
// - SOC0 will convert pin A0.
// - SOC1 will convert pin A1.
// - Both will be triggered by software only.
// - For 12-bit resolution, a sampling window of 15 (75 ns at a 200MHz
// SYSCLK rate) will be used. For 16-bit resolution, a sampling window
// of 64 (320 ns at a 200MHz SYSCLK rate) will be used.
//
#if(EX_ADC_RESOLUTION == 12)
ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_SW_ONLY,
ADC_CH_ADCIN1, 15);
ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER1, ADC_TRIGGER_SW_ONLY,
ADC_CH_ADCIN4, 15);
#elif(EX_ADC_RESOLUTION == 16)
ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_SW_ONLY,
ADC_CH_ADCIN0, 64);
ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER1, ADC_TRIGGER_SW_ONLY,
ADC_CH_ADCIN1, 64);
#endif
//
// Set SOC1 to set the interrupt 1 flag. Enable the interrupt and make
// sure its flag is cleared.
//
ADC_setInterruptSource(ADCA_BASE, ADC_INT_NUMBER1, ADC_SOC_NUMBER1);
ADC_enableInterrupt(ADCA_BASE, ADC_INT_NUMBER1);
ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);
//
// Configure SOCs of ADCB
// - SOC0 will convert pin B0.
// - SOC1 will convert pin B1.
// - Both will be triggered by software only.
// - For 12-bit resolution, a sampling window of 15 (75 ns at a 200MHz
// SYSCLK rate) will be used. For 16-bit resolution, a sampling window
// of 64 (320 ns at a 200MHz SYSCLK rate) will be used.
//
#if(EX_ADC_RESOLUTION == 12)
ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_SW_ONLY,
ADC_CH_ADCIN0, 15);
ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER1, ADC_TRIGGER_SW_ONLY,
ADC_CH_ADCIN1, 15);
#elif(EX_ADC_RESOLUTION == 16)
ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_SW_ONLY,
ADC_CH_ADCIN0, 64);
ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER1, ADC_TRIGGER_SW_ONLY,
ADC_CH_ADCIN1, 64);
#endif
//
// Set SOC1 to set the interrupt 1 flag. Enable the interrupt and make
// sure its flag is cleared.
//
ADC_setInterruptSource(ADCB_BASE, ADC_INT_NUMBER1, ADC_SOC_NUMBER1);
ADC_enableInterrupt(ADCB_BASE, ADC_INT_NUMBER1);
ADC_clearInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1);
}