test
Revision 3:63e99a7361ec, committed 2018-12-20
- Comitter:
- laik777
- Date:
- Thu Dec 20 08:29:12 2018 +0000
- Parent:
- 2:549286fb28d4
- Commit message:
- matej_slapsak;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Dec 11 07:20:30 2018 +0000
+++ b/main.cpp Thu Dec 20 08:29:12 2018 +0000
@@ -13,9 +13,6 @@
DigitalIn start3(p13);
DigitalIn start4(p10);
-//timerji
-Timer timerProgram;
-
//nastavitev pwm signalov
PwmOut pwm1 (p21);
PwmOut pwm2(p22);
@@ -32,6 +29,9 @@
float currentMeasH = 0.0;
float currentCalcH = 0.0;
+float PWM1 = 0.2f; //20% duty cycle
+float PWM2 = 0.6f; //60% duty cycle
+
//funkcija za nastavljanje baudrate pri serijski komunikaciji na PC
void baud(int baudrate)
{
@@ -45,9 +45,8 @@
printf ("<------- \r\n");
printf ("Measurement: \r\n");
DigitalOut pwmGD (p21);
- DigitalOut pwmHD (p22);
pwmGD = 1;
- pwmHD = 1;
+ //pwmHD = 1;
wait(0.1);
@@ -62,24 +61,21 @@
currentMeasH = measCurrH.read();
currentMeasH *= 3.3;
currentCalcH = currentMeasH * 1.279;
- wait(0.1);
+ wait(3);
printf("Voltage: %f V\r\n", voltageCalc);
printf("Current1: %f A\r\n", currentCalcG);
- printf("Current2: %f A\r\n", currentCalcH);
+ //printf("Current2: %f A\r\n", currentCalcH);
printf ("-------> \r\n");
pwmGD = 0;
- pwmHD = 0;
}
-
-
int main()
-{
+{
//hitrost serijske komunikacije
- baud(115200);
+ baud(9600);
while(1)
{
@@ -96,14 +92,21 @@
else if(start2 == 0)
{
+ //---------------SET
+ //signal duration
+ float t1 = 0.1;
+ float t2 = 0.2;
+ //duty cycle
+ //float PWM1 = 0.2f; //20% duty cycle
+ //float PWM2 = 0.6f; //60% duty cycle
+ //---------------SET
+
myled_green = ON;
PwmOut pwm1 (p21);
PwmOut pwm2(p22);
printf ("\r\n");
printf ("<------- \r\n");
- //merjenjeTokaInNapetosti();
-
//nastavitev pwm period
pwm1.period(0.001f);
pwm2.period(0.001f);
@@ -113,7 +116,7 @@
printf ("Start \r\n");
printf("pwm1 read: %f\n\r",pwm1.read());
- printf("pwm2 read: %f\n\r",pwm2.read());
+ //printf("pwm2 read: %f\n\r",pwm2.read());
//printf ("\r\n");
@@ -122,25 +125,25 @@
//izvajanje krmilja
printf ("PWM set \r\n");
- pwm1.write(0.2f);
+ pwm1.write(PWM1);
printf("pwm1 read: %f\n\r",pwm1.read());
- printf("pwm2 read: %f\n\r",pwm2.read());
- wait(0.1);
+ //printf("pwm2 read: %f\n\r",pwm2.read());
+ wait(t1);
printf ("PWM set \r\n");
- pwm1.write(0.6f);
+ pwm1.write(PWM2);
- printf("pwm1 read: %f\n\r",pwm1.read());
- printf("pwm2 read: %f\n\r",pwm2.read());
- wait(0.1);
+ printf("pwm2 read: %f\n\r",pwm1.read());
+ //printf("pwm2 read: %f\n\r",pwm2.read());
+ wait(t2);
printf ("PWM off \r\n");
pwm1 = 0;
pwm2 = 0;
printf("pwm1 read: %f\n\r",pwm1.read());
- printf("pwm2 read: %f\n\r",pwm2.read());
+ //printf("pwm2 read: %f\n\r",pwm2.read());
printf ("End \r\n");
printf ("-------> \r\n");
wait(2);
@@ -149,16 +152,43 @@
else if(start3 == 0)
{
+
+ if(PWM1 >= 1.0f)
+ {
+ PWM1 = 0.0f;
+ }
+
+ else
+ {
+ PWM1 = PWM1 + 0.1f;
+ }
+
+ printf("\n\r");
+ printf("PWM1: %f\n\r",PWM1);
+
myled_red = ON;
- wait(2);
+ wait(0.2);
}
else if(start4 == 0)
{
+ if(PWM2 >= 1.0f)
+ {
+ PWM2 = 0.0f;
+ }
+
+ else
+ {
+ PWM2 = PWM2 + 0.1f;
+ }
+
+ printf("\n\r");
+ printf("PWM2: %f\n\r",PWM2);
+
myled_blue = ON;
myled_red = ON;
myled_green = ON;
- wait(2);
+ wait(0.2);
}
}