For those of you familiar with diffs, here are the diffs for user_routines.c and user_routines_fast.c, so that you can get an idea how to use the PPM4VEX library:
user_routines.c:
--- VexCode/user_routines.c 2008-11-30 16:37:39.000000000 -0800
+++ PPM4VEX/user_routines.c 2008-11-30 16:45:25.000000000 -0800
@@ -15,6 +15,7 @@
#include "ifi_utilities.h"
#include "user_routines.h"
#include "printf_lib.h"
+#include "PPM4VEX.h"
#define CODE_VERSION 2 /* Use this def. to keep track of your version # */
@@ -190,13 +191,13 @@
pwm01 = pwm02 = pwm03 = pwm04 = pwm05 = pwm06 = pwm07 = pwm08 = 127;
/* SEVENTH: Choose which processor will control which PWM outputs. */
- Setup_Who_Controls_Pwms(MASTER,MASTER,MASTER,MASTER,MASTER,MASTER,MASTER,MASTER);
+ Setup_Who_Controls_Pwms(USER,MASTER,MASTER,MASTER,MASTER,MASTER,MASTER,MASTER);
/* EIGHTH: Set your PWM output type. Only applies if USER controls PWM 1, 2, 3, or 4. */
/* Choose from these parameters for PWM 1-4 respectively: */
/* IFI_PWM - Standard IFI PWM output generated with Generate_Pwms(...) */
/* USER_CCP - User can use PWM pin as digital I/O or CCP pin. */
- Setup_PWM_Output_Type(IFI_PWM,IFI_PWM,IFI_PWM,IFI_PWM);
+ Setup_PWM_Output_Type(USER_CCP,IFI_PWM,IFI_PWM,IFI_PWM);
/*
Example: The following would generate a 40KHz PWM with a 50% duty cycle
@@ -226,6 +227,7 @@
Getdata(&rxdata);
printf("VEX - Master v%d, User v%d\n",(int)rxdata.master_version,(int)CODE_VERSION);
#endif
+ PPM_Initialization();
}
@@ -241,13 +243,53 @@
{
Getdata(&rxdata); /* Get fresh data from the master microprocessor. */
+#define PPM_DEMO1
+/* PPM Demo 1 - This demo simply duplicates the pwm settings for the built-in
+ * motor ports to the corresponding channels on the PPM port.
+ * Note that Motor Port 1 is used for the PPM signal to the slave controller.
+ */
+#ifdef PPM_DEMO1
Default_Routine(); /* Optional. See below. */
/* Add your own code here. */
- printf("%2x : %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x\n",(int)rxdata.rc_receiver_status_byte.allbits,
- (int)PWM_in1,(int)PWM_in2,(int)PWM_in3,(int)PWM_in4,(int)PWM_in5,
- (int)PWM_in6,(int)PWM_in7,(int)PWM_in8,(int)PWM_in9,(int)PWM_in10,
- (int)PWM_in11,(int)PWM_in12); /* printf EXAMPLE */
+ ppm1[1] = pwm01;
+ ppm1[2] = pwm02;
+ ppm1[3] = pwm03;
+ ppm1[4] = pwm04;
+ ppm1[5] = pwm05;
+ ppm1[6] = pwm06;
+ PPM_Generate_Pwms();
+#endif
+
+
+//#define PPM_DEMO2
+/* PPM Demo 2 - This demo slowly ramps motor port 4 from 0 to 255 and back in
+ * a pattern that looks like a triangle wave. Motor port 3 switches between
+ * 0 and 255 every 5 seconds or so. PPM channels 3&4 track motor ports 3&4.
+ * Note that Motor Port 1 is used for the PPM signal to the slave controller.
+ */
+#ifdef PPM_DEMO2
+ if (pwm03) {
+ if (pwm04 < 255) {
+ pwm04++;
+ } else {
+ pwm03 = 0;
+ printf("PPM Demo 2 - reversing direction -\n");
+ }
+ } else {
+ if (pwm04 > 0) {
+ pwm04--;
+ } else {
+ pwm03 = 255;
+ printf("PPM Demo 2 - reversing direction +\n");
+ }
+ }
+
+ ppm1[3] = pwm03; // gang ppm channel 3 to motor port 3
+ ppm1[4] = pwm04; // gang ppm channel 4 to motor port 4
+
+ PPM_Generate_Pwms();
+#endif
Putdata(&txdata); /* DO NOT CHANGE! */
}
user_routines_fast.c:
--- VexCode/user_routines_fast.c 2008-11-30 16:37:39.000000000 -0800
+++ PPM4VEX/user_routines_fast.c 2008-11-30 16:42:51.000000000 -0800
@@ -19,6 +19,7 @@
#include "user_routines.h"
#include "printf_lib.h"
#include "delays.h"
+#include "PPM4VEX.h" // ppm interrupt handler(s)
/*** DEFINE USER VARIABLES AND INITIALIZE THEM HERE ***/
@@ -73,6 +74,10 @@
int_byte = PORTB; /* You must read or write to PORTB */
INTCONbits.RBIF = 0; /* and clear the interrupt flag */
} /* to clear the interrupt condition. */
+ else
+ {
+ PPM_Interrupt();
+ }
}
Cheers,