Robotic_winteam / Mbed 2 deprecated Nucleo_pwmdecoder

Dependencies:   mbed

main.cpp

Committer:
ooseausername
Date:
2016-05-24
Revision:
0:97b4f9625db2
Child:
1:836ed9afcb8a

File content as of revision 0:97b4f9625db2:

#include "mbed.h"

PwmOut mypwm(PWM_OUT);

DigitalOut myled(LED1);

int main() {
    
    mypwm.period_ms(10);
    mypwm.pulsewidth_ms(1);
  
    printf("pwm set to %.2f %%\n", mypwm.read() * 100);
    
    while(1) {
        myled = !myled;
        wait(1);
    }
}
void _ISR _U2RXInterrupt(void)
{

static char Temp;
Temp=U2RXREG;
if (Receive_Flag==1)
{
Receive_Counter++;
Receive_Data[Receive_Counter]=Temp;

if(Receive_Counter==9)
{
Command_Flag=1;
Receive_Flag=0;
Receive_Counter=0;
}
}
else
{
if(Temp==36)
{
Receive_Flag=1;
Receive_Counter=0;
Receive_Data[0]= Temp;
}
else
{
}
}
IFS1bits.U2RXIF=0;
}


if(Command_Flag==1)
{
Position_Error=(Receive_Data[2]-0x30)*100+(Receive_Data[3]-0x30)*10+(Receive_Data[4]-0x30);

if(Receive_Data[1]=='-')
Position_Error=-1*Position_Error;
else Position_Error=Position_Error; 

Degree_Error=(Receive_Data[6]-0x30)*100+(Receive_Data[7]-0x30)*10+(Receive_Data[8]-0x30);

if(Receive_Data[5]=='-')
Degree_Error=-1*Degree_Error;
else Degree_Error=Degree_Error;
if(Receive_Data[9]=='j') pwm_duty=148;
else if (Receive_Data[9]=='k') pwm_duty=100;
Command_Flag=0;
}