For communication between GR Peach and FPGA using PWM.

Dependencies:   mbed-rtos mbed

Committer:
akverma
Date:
Sat Dec 03 07:39:39 2016 +0000
Revision:
1:769aa85d78de
Parent:
0:46fb3f8071e7
Updated for checking.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
akverma 1:769aa85d78de 1 //I am adding this comment to ust see the changes in repository.
akverma 1:769aa85d78de 2
akverma 0:46fb3f8071e7 3 #include "mbed.h"
akverma 0:46fb3f8071e7 4 #include "rtos.h"
akverma 0:46fb3f8071e7 5
akverma 0:46fb3f8071e7 6 DigitalOut led1(P8_13);
akverma 0:46fb3f8071e7 7 DigitalOut led2(LED2);
akverma 0:46fb3f8071e7 8 DigitalOut led3(LED3);
akverma 0:46fb3f8071e7 9 DigitalOut dataOutFPGA(P8_11);
akverma 0:46fb3f8071e7 10
akverma 0:46fb3f8071e7 11 uint8_t data[3];
akverma 0:46fb3f8071e7 12 const int factor = 100;
akverma 0:46fb3f8071e7 13
akverma 0:46fb3f8071e7 14 /*void send_fpga_thread ()//void const *args)
akverma 0:46fb3f8071e7 15 {
akverma 0:46fb3f8071e7 16 led1 = 1;
akverma 0:46fb3f8071e7 17 wait_us((data[0]+1)*1000);
akverma 0:46fb3f8071e7 18 led1 = 0;
akverma 0:46fb3f8071e7 19 wait_us((255-data[0])*1000);
akverma 0:46fb3f8071e7 20 led1 = 1;
akverma 0:46fb3f8071e7 21 wait_us((data[1]+1)*1000);
akverma 0:46fb3f8071e7 22 led1 = 0;
akverma 0:46fb3f8071e7 23 wait_us((255-data[1])*1000);
akverma 0:46fb3f8071e7 24 led1 = 1;
akverma 0:46fb3f8071e7 25 wait_us((data[2]+1)*1000);
akverma 0:46fb3f8071e7 26 led1 = 0;
akverma 0:46fb3f8071e7 27 wait_us((255-data[2])*1000);
akverma 0:46fb3f8071e7 28 }*/
akverma 0:46fb3f8071e7 29
akverma 0:46fb3f8071e7 30 /*void send_fpga_thread ()//void const *args)
akverma 0:46fb3f8071e7 31 {
akverma 0:46fb3f8071e7 32 led1 = 1;
akverma 0:46fb3f8071e7 33 wait_us((data[0]+1));
akverma 0:46fb3f8071e7 34 led1 = 0;
akverma 0:46fb3f8071e7 35 wait_us((255-data[0]));
akverma 0:46fb3f8071e7 36 led1 = 1;
akverma 0:46fb3f8071e7 37 wait_us((data[1]+1));
akverma 0:46fb3f8071e7 38 led1 = 0;
akverma 0:46fb3f8071e7 39 wait_us((255-data[1]));
akverma 0:46fb3f8071e7 40 led1 = 1;
akverma 0:46fb3f8071e7 41 wait_us((data[2]+1));
akverma 0:46fb3f8071e7 42 led1 = 0;
akverma 0:46fb3f8071e7 43 wait_us((255-data[2]));
akverma 0:46fb3f8071e7 44 }*/
akverma 0:46fb3f8071e7 45
akverma 0:46fb3f8071e7 46 void send_fpga_thread ()//void const *args)
akverma 0:46fb3f8071e7 47 {
akverma 0:46fb3f8071e7 48 led1 = 1;
akverma 0:46fb3f8071e7 49 wait_us(factor*(data[0]+1));
akverma 0:46fb3f8071e7 50 led1 = 0;
akverma 0:46fb3f8071e7 51 wait_us(factor*(255-data[0]));
akverma 0:46fb3f8071e7 52 led1 = 1;
akverma 0:46fb3f8071e7 53 wait_us(factor*(data[1]+1));
akverma 0:46fb3f8071e7 54 led1 = 0;
akverma 0:46fb3f8071e7 55 wait_us(factor*(255-data[1]));
akverma 0:46fb3f8071e7 56 led1 = 1;
akverma 0:46fb3f8071e7 57 wait_us(factor*(data[2]+1));
akverma 0:46fb3f8071e7 58 led1 = 0;
akverma 0:46fb3f8071e7 59 wait_us(factor*(255-data[2]));
akverma 0:46fb3f8071e7 60 }
akverma 0:46fb3f8071e7 61
akverma 0:46fb3f8071e7 62 int main() {
akverma 0:46fb3f8071e7 63 led1=0;
akverma 0:46fb3f8071e7 64 data[0] = 0x44;
akverma 0:46fb3f8071e7 65 data[1] = 0x82;
akverma 0:46fb3f8071e7 66 data[2] = 0xC1;
akverma 0:46fb3f8071e7 67 wait(3);
akverma 0:46fb3f8071e7 68 //Thread thread(blink_thread);
akverma 0:46fb3f8071e7 69 //Thread thread(send_fpga_thread);
akverma 0:46fb3f8071e7 70 send_fpga_thread();
akverma 0:46fb3f8071e7 71 while (true)
akverma 0:46fb3f8071e7 72 {
akverma 0:46fb3f8071e7 73 led2=!led2;
akverma 0:46fb3f8071e7 74 wait_ms(100);
akverma 0:46fb3f8071e7 75 }
akverma 0:46fb3f8071e7 76 }