GR_Peach_Abhinav_Rahul
/
pwm_send_fpga
For communication between GR Peach and FPGA using PWM.
main.cpp@0:46fb3f8071e7, 2016-12-03 (annotated)
- Committer:
- akverma
- Date:
- Sat Dec 03 07:35:23 2016 +0000
- Revision:
- 0:46fb3f8071e7
- Child:
- 1:769aa85d78de
PWM communication with FPGA.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akverma | 0:46fb3f8071e7 | 1 | #include "mbed.h" |
akverma | 0:46fb3f8071e7 | 2 | #include "rtos.h" |
akverma | 0:46fb3f8071e7 | 3 | |
akverma | 0:46fb3f8071e7 | 4 | DigitalOut led1(P8_13); |
akverma | 0:46fb3f8071e7 | 5 | DigitalOut led2(LED2); |
akverma | 0:46fb3f8071e7 | 6 | DigitalOut led3(LED3); |
akverma | 0:46fb3f8071e7 | 7 | DigitalOut dataOutFPGA(P8_11); |
akverma | 0:46fb3f8071e7 | 8 | |
akverma | 0:46fb3f8071e7 | 9 | uint8_t data[3]; |
akverma | 0:46fb3f8071e7 | 10 | const int factor = 100; |
akverma | 0:46fb3f8071e7 | 11 | |
akverma | 0:46fb3f8071e7 | 12 | /*void send_fpga_thread ()//void const *args) |
akverma | 0:46fb3f8071e7 | 13 | { |
akverma | 0:46fb3f8071e7 | 14 | led1 = 1; |
akverma | 0:46fb3f8071e7 | 15 | wait_us((data[0]+1)*1000); |
akverma | 0:46fb3f8071e7 | 16 | led1 = 0; |
akverma | 0:46fb3f8071e7 | 17 | wait_us((255-data[0])*1000); |
akverma | 0:46fb3f8071e7 | 18 | led1 = 1; |
akverma | 0:46fb3f8071e7 | 19 | wait_us((data[1]+1)*1000); |
akverma | 0:46fb3f8071e7 | 20 | led1 = 0; |
akverma | 0:46fb3f8071e7 | 21 | wait_us((255-data[1])*1000); |
akverma | 0:46fb3f8071e7 | 22 | led1 = 1; |
akverma | 0:46fb3f8071e7 | 23 | wait_us((data[2]+1)*1000); |
akverma | 0:46fb3f8071e7 | 24 | led1 = 0; |
akverma | 0:46fb3f8071e7 | 25 | wait_us((255-data[2])*1000); |
akverma | 0:46fb3f8071e7 | 26 | }*/ |
akverma | 0:46fb3f8071e7 | 27 | |
akverma | 0:46fb3f8071e7 | 28 | /*void send_fpga_thread ()//void const *args) |
akverma | 0:46fb3f8071e7 | 29 | { |
akverma | 0:46fb3f8071e7 | 30 | led1 = 1; |
akverma | 0:46fb3f8071e7 | 31 | wait_us((data[0]+1)); |
akverma | 0:46fb3f8071e7 | 32 | led1 = 0; |
akverma | 0:46fb3f8071e7 | 33 | wait_us((255-data[0])); |
akverma | 0:46fb3f8071e7 | 34 | led1 = 1; |
akverma | 0:46fb3f8071e7 | 35 | wait_us((data[1]+1)); |
akverma | 0:46fb3f8071e7 | 36 | led1 = 0; |
akverma | 0:46fb3f8071e7 | 37 | wait_us((255-data[1])); |
akverma | 0:46fb3f8071e7 | 38 | led1 = 1; |
akverma | 0:46fb3f8071e7 | 39 | wait_us((data[2]+1)); |
akverma | 0:46fb3f8071e7 | 40 | led1 = 0; |
akverma | 0:46fb3f8071e7 | 41 | wait_us((255-data[2])); |
akverma | 0:46fb3f8071e7 | 42 | }*/ |
akverma | 0:46fb3f8071e7 | 43 | |
akverma | 0:46fb3f8071e7 | 44 | void send_fpga_thread ()//void const *args) |
akverma | 0:46fb3f8071e7 | 45 | { |
akverma | 0:46fb3f8071e7 | 46 | led1 = 1; |
akverma | 0:46fb3f8071e7 | 47 | wait_us(factor*(data[0]+1)); |
akverma | 0:46fb3f8071e7 | 48 | led1 = 0; |
akverma | 0:46fb3f8071e7 | 49 | wait_us(factor*(255-data[0])); |
akverma | 0:46fb3f8071e7 | 50 | led1 = 1; |
akverma | 0:46fb3f8071e7 | 51 | wait_us(factor*(data[1]+1)); |
akverma | 0:46fb3f8071e7 | 52 | led1 = 0; |
akverma | 0:46fb3f8071e7 | 53 | wait_us(factor*(255-data[1])); |
akverma | 0:46fb3f8071e7 | 54 | led1 = 1; |
akverma | 0:46fb3f8071e7 | 55 | wait_us(factor*(data[2]+1)); |
akverma | 0:46fb3f8071e7 | 56 | led1 = 0; |
akverma | 0:46fb3f8071e7 | 57 | wait_us(factor*(255-data[2])); |
akverma | 0:46fb3f8071e7 | 58 | } |
akverma | 0:46fb3f8071e7 | 59 | |
akverma | 0:46fb3f8071e7 | 60 | int main() { |
akverma | 0:46fb3f8071e7 | 61 | led1=0; |
akverma | 0:46fb3f8071e7 | 62 | data[0] = 0x44; |
akverma | 0:46fb3f8071e7 | 63 | data[1] = 0x82; |
akverma | 0:46fb3f8071e7 | 64 | data[2] = 0xC1; |
akverma | 0:46fb3f8071e7 | 65 | wait(3); |
akverma | 0:46fb3f8071e7 | 66 | //Thread thread(blink_thread); |
akverma | 0:46fb3f8071e7 | 67 | //Thread thread(send_fpga_thread); |
akverma | 0:46fb3f8071e7 | 68 | send_fpga_thread(); |
akverma | 0:46fb3f8071e7 | 69 | while (true) |
akverma | 0:46fb3f8071e7 | 70 | { |
akverma | 0:46fb3f8071e7 | 71 | led2=!led2; |
akverma | 0:46fb3f8071e7 | 72 | wait_ms(100); |
akverma | 0:46fb3f8071e7 | 73 | } |
akverma | 0:46fb3f8071e7 | 74 | } |