Hi,
I want to read a Voltage from the Analog In 1 Pin and output that Voltage in a CAN message.
How do I do this using the PCAN Router Pro FD?
Best regards,
Tim
Read Voltage from Analog In
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: Read Voltage from Analog In
if you take a look into the Sample 08_HW_IO and check in the main.c / line 120 , you will find this code
The AD have 12Bit, and the Result is 8.13mV per Digit.
We will extend this in the next Version to an own Function like the DIn.
Code: Select all
// clear EOC flag by read the ADC2 register
TempVar = ADC2->DR & 0xFFF;
ADC2->SQR3 = 6;
ADC2->CR2 |= 1 << 30;
// wait EOC flag
while ( !( ADC2->SR & ( 1 << 1)))
{}
ResultData = ADC2->DR & 0xFFF;
We will extend this in the next Version to an own Function like the DIn.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: Read Voltage from Analog In
We have add the HW_GetAIN to the code - so now you simply call the function to get the Analogue value.
Here a sample - CAN ID 0x55A / STD Msg, trigger the function and send the result on 0x55B in the first 16 Bits (Byte 0 and 1)
Here the new Block in "hardware.h"
Here a sample - CAN ID 0x55A / STD Msg, trigger the function and send the result on 0x55B in the first 16 Bits (Byte 0 and 1)
Code: Select all
uint32_t tmp32;
// catch ID 55Ah to send analog value from AIN
if ( RxMsg.id == 0x55A && RxMsg.msgtype == CAN_MSGTYPE_STANDARD)
{
HW_GetAIN ( &tmp32);
RxMsg.id = RxMsg.id + 1;
RxMsg.data16[0] = tmp32;
CAN_Write ( CAN_BUS1, &RxMsg);
}
Code: Select all
//! @brief get AIN from I/O pins
//!
//! @param buffer result buffer (single uint32_t)
//!
//! @return one error of HW_ERR_...
HWResult_t HW_GetAIN ( uint32_t *buffer);
//! @brief
//! Read digital inputs. Each bit will represent a digital pin.
//!
//! @param buffer Buffer for DIN-value
//!
//! @return one error of HW_ERR_...
HWResult_t HW_GetDIN ( uint32_t *buffer);
//! @brief
//! Set digital outputs. Each bit will represent a digital pin.
//!
//! @param buffer Buffer for DOUT-value
//!
//! @return one error of HW_ERR_...
HWResult_t HW_SetDOUT ( uint32_t *buffer);
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------