MCU & PLC

MCU보드에 24V 입력을 받아보자 (24V -> 3V 레귤레이터)

sheepone 2021. 5. 21. 17:03
반응형
레귤레이터 사용 이유
통신으로 시작 시점을 정하기에는 딜레이가 있어 IO를 사용하여
시작시점을 동일하게 맞추기 위해 입출력을 사용.

PLC나 PC자동화 장비에서 사용하는 출력은 기본 24V로 해당 출력을 다이렉트로 받아올 수 없어 레귤레이터를 사용하여 24V 를 3V로 강하 하여 사용한다.
(EK-TM4C1294XL 보드의 경우 기본 출력시 3.2V 정도 출력되며 입력 3V 필요)

 

사용제품

LM2596 DC-DC 스텝다운 컨버터

블로그 쓰다 보니 알았는데 처음에 주문한 제품은 
LM2577 + LM2596 강하형 DC-DC 가변(자동) 컨버터 [SZH-PWSD-049] 7150원 짜리 였는데
온 제품은 LM2596 DC-DC 스텝다운 컨버터 700원 짜리 제품 이엿다...
이미 구매 확정도 하고 테스트 까지 완료 햇는데...ㅠㅠ

사용에는 LM2596 DC-DC 스텝다운 컨버터 700원 짜리 제품이 문제가 없으니 700원 짜리로 구매 하도록 하자.

 

연결 방법
IN+ 에는 P24
IN- 에는 N24
OUT+ 에는 PN2 (예제에 보면 해당핀을 사용)
OUT- 에는 GND (해당핀 근처의 그라운드 사용)

 

사용 예제
//*****************************************************************************
//
// blinky.c - Simple example to blink the on-board LED.
//
// Copyright (c) 2013-2017 Texas Instruments Incorporated.  All rights reserved.
// Software License Agreement
// 
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
// 
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
// 
// This is part of revision 2.1.4.178 of the EK-TM4C1294XL Firmware Package.
//
//*****************************************************************************

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"

//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>Blinky (blinky)</h1>
//!
//! A very simple example that blinks the on-board LED using direct register
//! access.
//
//*****************************************************************************

//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
    while(1);
}
#endif

//*****************************************************************************
//
// Blink the on-board LED.
//
//*****************************************************************************
int
main(void)
{
    volatile uint32_t ui32Loop;

    //
    // Enable the GPIO port that is used for the on-board LED.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);

    //
    // Check if the peripheral access is enabled.
    //
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION))
    {
    }

    //
    // Enable the GPIO pin for the LED (PN0).  Set the direction as output, and
    // enable the GPIO pin for digital function.
    //
    GPIOPinTypeGPIOInput(GPIO_PORTN_BASE, GPIO_PIN_2);
    GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0);

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Turn on the LED (With PN0,PN2)
        //

        //GPIO_PIN_2 -> PN2에 3V입력이 들어왔을때 
        //GPIO_PIN_0 -> PN0을 ON (PN0,PN1은 LED가 있음)
        if(GPIOPinRead(GPIO_PORTN_BASE, GPIO_PIN_2)){
            GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0);
        }
        //GPIO_PIN_2 -> PN2에 3V입력이 안들어와 있을때 
        //GPIO_PIN_0 -> PN0을 OFF (PN0,PN1은 LED가 있음)
        else{
            GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x0);
        }
    }
}
반응형