// experi7b.c #include #include #include // defines OC structure #include "outcont.h" // include header with constants #include "constant.h" // include header with external prototypes #include "extern.h" enum { MainMotor, LED1, LED2, LASTSLOT }; void main(void) { int x; double dc,oldfreq,newfreq; oldfreq = 1193180.0/65536.0; get_port(); // get the port number and establish register locations // make everthing an output set_up_ppi(Aout_CUout_Bout_CLout); set_up_new_timer(2000.0); newfreq = get_frequency(); printf("old frequency = %f new frequency = %f Hz\n" ,oldfreq,newfreq); // set up a dual pwm channel using duty cycle DualPwmDuty(MainMotor, 0, // set up, but don't start main motor PA0, 75.0, // forward uses line PA0 at 75% PA1, 15.0); // reverse uses line PA1 at 15% Blink(LED1, PA2, .3, .2); Blink(LED2, PA3, .15, .1); SetLast(LASTSLOT); printf("MainMotor settings with 75%% forward and 15%% reverse:\n"); show(MainMotor); printf("LEDs should be blinking and pwm off -- press any key to start test\n"); getch(); while(!kbhit()) { printf("forward 75%% 2 seconds\n"); Forward(MainMotor); wait(2.0); // wait 2 seconds to be kind to power supply printf("stop 2 seconds\n"); Stop(MainMotor); wait(2.0); // wait 2 seconds to be kind to power supply printf("reverse 15%% 2 seconds\n"); Reverse(MainMotor); wait(2.0); // wait 2 seconds to be kind to power supply printf("stop 2 seconds\n"); Stop(MainMotor); wait(2.0); // wait 2 seconds to be kind to power supply } portaoff(); portboff(); portboff(); // don't forget to free memory! FreeOutputControl(); // be sure to restore the timer! restore_old_timer(); } // end experi7b.c