GR_Peach_Abhinav_Rahul
/
pwm_send_fpga
For communication between GR Peach and FPGA using PWM.
Diff: main.cpp
- Revision:
- 0:46fb3f8071e7
- Child:
- 1:769aa85d78de
diff -r 000000000000 -r 46fb3f8071e7 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Dec 03 07:35:23 2016 +0000 @@ -0,0 +1,74 @@ +#include "mbed.h" +#include "rtos.h" + +DigitalOut led1(P8_13); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut dataOutFPGA(P8_11); + +uint8_t data[3]; +const int factor = 100; + +/*void send_fpga_thread ()//void const *args) +{ + led1 = 1; + wait_us((data[0]+1)*1000); + led1 = 0; + wait_us((255-data[0])*1000); + led1 = 1; + wait_us((data[1]+1)*1000); + led1 = 0; + wait_us((255-data[1])*1000); + led1 = 1; + wait_us((data[2]+1)*1000); + led1 = 0; + wait_us((255-data[2])*1000); +}*/ + +/*void send_fpga_thread ()//void const *args) +{ + led1 = 1; + wait_us((data[0]+1)); + led1 = 0; + wait_us((255-data[0])); + led1 = 1; + wait_us((data[1]+1)); + led1 = 0; + wait_us((255-data[1])); + led1 = 1; + wait_us((data[2]+1)); + led1 = 0; + wait_us((255-data[2])); +}*/ + +void send_fpga_thread ()//void const *args) +{ + led1 = 1; + wait_us(factor*(data[0]+1)); + led1 = 0; + wait_us(factor*(255-data[0])); + led1 = 1; + wait_us(factor*(data[1]+1)); + led1 = 0; + wait_us(factor*(255-data[1])); + led1 = 1; + wait_us(factor*(data[2]+1)); + led1 = 0; + wait_us(factor*(255-data[2])); +} + +int main() { + led1=0; + data[0] = 0x44; + data[1] = 0x82; + data[2] = 0xC1; + wait(3); + //Thread thread(blink_thread); + //Thread thread(send_fpga_thread); + send_fpga_thread(); + while (true) + { + led2=!led2; + wait_ms(100); + } +}