반응형
ADC로 전압측정해서 7-Segment로 전압 출력하는 프로그램.
7Segment 로 입력전압을 측정결과를 출력해야 하는데
7세그먼트가 맛이 간것인지.... 불이 안들어오는 부분이 많아서 테스트를 제대로 못해봤다.
그래서 대충~ 전압값에 따라서 다른핀으로 출력을 하도록 만들었는데 뭔가 좀 잘못된듯 하다. -_-;;
7segment 를 다시 구해서 잘 해봐야 겠다.
약간의 삽질을 해본 결과 몇개의 7 Segment는 맛이간것이 맞았다.
하다가 보니까 LED 들어오는지 확인할 수 있는 핀이 있었다는것을 알아냈다. ㅋ 써있는데도 모르고 있다가 우연히 꼽았는데 알게되었다. light 테스트 핀에 연결하니 확실하게 테스트가 가능했다.
CPU 특성상 3V 에 해상도가 1K라서 Voltage 계산법이 저렇게 되어있다.
- #include "../../../hw_ints.h"
- #include "../../../hw_adc.h"
- #include "../../../hw_memmap.h"
- #include "../../../hw_types.h"
- #include "../../../src/debug.h"
- #include "../../../src/gpio.h"
- #include "../../../src/adc.h"
- #include "../../../src/interrupt.h"
- #include "../../../src/sysctl.h"
- #include "../../../src/watchdog.h"
- #include "../../../src/timer.h"
- #include "../rit128x96x4.h"
- //*****************************************************************************
- //
- //! \addtogroup ek_lm3s8962_list
- //! <h1>Watchdog (watchdog)</h1>
- //!
- //! This example application demonstrates the use of the watchdog as a simple
- //! heartbeat for the system. If the watchdog is not periodically fed, it will
- //! reset the system. Each time the watchdog is fed, the LED is inverted so
- //! that it is easy to see that it is being fed, which occurs once every
- //! second.
- //
- //*****************************************************************************
- //*****************************************************************************
- //
- // The error routine that is called if the driver library encounters an error.
- //
- //*****************************************************************************
- #ifdef DEBUG
- void
- __error__(char *pcFilename, unsigned long ulLine)
- {
- }
- #endif
- //*****************************************************************************
- // The interrupt handler for the watchdog. This feeds the dog (so that the
- // processor does not get reset) and winks the LED.
- //*****************************************************************************
- void
- WatchdogIntHandler(void)
- {
- /*
- //
- // Clear the watchdog interrupt.
- //
- WatchdogIntClear(WATCHDOG_BASE);
- //
- // Invert the GPIO F0 value.
- //
- GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0,
- GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0) ^ GPIO_PIN_0);
- */
- }
- void myTimer(void);
- void printNUM(unsigned int num);
- void printNUM2(unsigned int num);
- int main(void)
- {
- // Set the clocking to run directly from the crystal.
- SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
- SYSCTL_XTAL_8MHZ);
- ///GPIOA Set, ADC, Timer Set
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); //port A enable
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); //port C enable
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //port D enable
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); //port G enable
- SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC); //ADC enable
- SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //Timer0 enable
- //ADCProcessorTrigger()에서 ADC 시작. 프로세서 트리거가 일어날때 작동한다.
- ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
- //ADC0의 sequence를 구성한다.sequence number 0인 ADC를 single ended mode로 setting
- ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH0);
- //ADC를 사용 가능하게 해준다.
- ADCSequenceEnable(ADC_BASE, 0);
- //Port A1,3,5,G0 set to output type
- GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_1); //A1
- GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_3); //A3
- GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_5); //A5
- GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_4); //C4
- GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_6); //C6
- GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_1); //D1
- GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_3); //D3
- GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_0); //G0
- GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_1); //G1
- TimerConfigure(TIMER0_BASE,TIMER_CFG_32_BIT_PER); //32-BIT PERIODIC TIMER
- TimerLoadSet(TIMER0_BASE,TIMER_A,6000000);
- TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);//Timer0 interrupt enable
- TimerIntRegister(TIMER0_BASE,TIMER_A, myTimer); //timer interrupt 발생시 myTimer 라는 함수의 이벤트 발생
- TimerEnable(TIMER0_BASE,TIMER_A); //Timer Start
- while(1){}
- }
- void myTimer(void)
- {
- unsigned int Voltage;
- unsigned long ulValue;
- unsigned long readGPIO;
- unsigned int i;
- //This function triggers a processor-initiated sample sequence if the sample sequence trigger is
- //configured to ADC_TRIGGER_PROCESSOR.
- ADCProcessorTrigger(ADC_BASE, 0);
- //sample sequence 가 완료될때 까지 대기한다.
- while(!ADCIntStatus(ADC_BASE, 0, false)){}
- // Read the value from the ADC.
- ADCSequenceDataGet(ADC_BASE, 0, &ulValue);//전압 값을 받아옴
- Voltage = (int)((3.0/1023)*ulValue*10);
- //-----------폼으로 껌뻑이게 했음----------------------//
- if(GPIOPinRead(GPIO_PORTG_BASE,GPIO_PIN_0))
- GPIOPinWrite(GPIO_PORTG_BASE,GPIO_PIN_0,0);
- else
- GPIOPinWrite(GPIO_PORTG_BASE,GPIO_PIN_0,GPIO_PIN_0);
- //-----------폼으로 껌뻑이게 했음----------------------//
- printNUM(Voltage%10);
- printNUM2(Voltage/10);
- TimerIntClear(TIMER0_BASE,TIMER_TIMA_TIMEOUT);//Timer Interupt clear
- }
- void printNUM(unsigned int num)
- {
- if (num&1)
- GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_5,GPIO_PIN_5);
- else
- GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_5,0);
- if (num&2)
- GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,GPIO_PIN_3);
- else
- GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0);
- if (num&4)
- GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_1,GPIO_PIN_1);
- else
- GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_1,0);
- if (num&8)
- GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_4,GPIO_PIN_4);
- else
- GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_4,0);
- }
- void printNUM2(unsigned int num)
- {
- if (num&1)
- GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_6,GPIO_PIN_6);
- else
- GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_6,0);
- if (num&2)
- GPIOPinWrite(GPIO_PORTG_BASE,GPIO_PIN_1,GPIO_PIN_1);
- else
- GPIOPinWrite(GPIO_PORTG_BASE,GPIO_PIN_1,0);
- if (num&4)
- GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_3,GPIO_PIN_3);
- else
- GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_3,0);
- if (num&8)
- GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_1,GPIO_PIN_1);
- else
- GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_1,0);
- }
7세그먼트가 맛이 간것인지.... 불이 안들어오는 부분이 많아서 테스트를 제대로 못해봤다.
그래서 대충~ 전압값에 따라서 다른핀으로 출력을 하도록 만들었는데 뭔가 좀 잘못된듯 하다. -_-;;
7segment 를 다시 구해서 잘 해봐야 겠다.
하다가 보니까 LED 들어오는지 확인할 수 있는 핀이 있었다는것을 알아냈다. ㅋ 써있는데도 모르고 있다가 우연히 꼽았는데 알게되었다. light 테스트 핀에 연결하니 확실하게 테스트가 가능했다.
CPU 특성상 3V 에 해상도가 1K라서 Voltage 계산법이 저렇게 되어있다.
반응형
'Embeded' 카테고리의 다른 글
터치스크린 쓰기. (0) | 2009.01.23 |
---|---|
Timer 사용하기 (0) | 2009.01.05 |
LM3S8962 GPIO 연습 코드 (0) | 2009.01.02 |