For communication between GR Peach and FPGA using PWM.

Dependencies:   mbed-rtos mbed

main.cpp

Committer:
akverma
Date:
2016-12-03
Revision:
0:46fb3f8071e7
Child:
1:769aa85d78de

File content as of revision 0:46fb3f8071e7:

#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);
        }
}