Terminal Question
Beavis3215
Posts: 229
in Propeller 1
/* Fidget Spinner Motor Auto time version Pin 19 is on sensor input Pin 18 is off sensor input Pin 17 is magnet controller output Pin 16 is timing light output Pin 15 is timing advance input Pin 14 is timing retard input Pin 13-8 is binary timing output */ #include "simpletools.h" // Include simple tools void button_time(); void time_it(); static volatile int delay, on_sensor, off_sensor; //all global int main() // Main function { clkset(0b01101111, 80000000); cog_run(button_time,128); // Push button control runs in other cog cog_run(time_it,128); // Times magnet on sensor to magnet off sensor on_sensor = 1 << 19; off_sensor = 1 << 18; int magnet = 1 << 17; int t_light = 1 << 16; DIRA &= ~(1 << 19); DIRA &= ~(1 << 18); DIRA |= (magnet); DIRA |= (t_light); while(1) { if ((INA & on_sensor) == on_sensor) // If on sensor high { OUTA |= (magnet); // Turn magnet on } if ((INA & off_sensor) == off_sensor) // If off sensor high { pause(delay); // Delay is assigned in button_time OUTA &= ~(magnet); // Turn magnet off OUTA |= (t_light); // Timing light on pause(1); OUTA &= ~(t_light); // Timing light off } } } void button_time() { int lights = 0b111111 << 8; //Timing delay LED's int advance = 1 << 15; int retard = 1 << 14; DIRA &= ~(advance); DIRA &= ~(retard); DIRA |= (lights); int t = 20; while(1) { if ((INA & retard) == retard) // If retard button high { t++ ; if (t > 64) // Don't allow t to exceed 64 { t = 64; } } if ((INA & advance) == advance) // If advance button high { t-- ; if (t < 1) // Keep t 1 or larger { t = 1; } } delay = t; // Pass delay to main function OUTA = (OUTA & ~(lights)) | (t << 8 ); // Put t value on output lights pause(300); } } void time_it() { unsigned int uS, t_initial, t_final; int pass_number = 0; int total_passes = 10; int total = 0; uS = CLKFREQ/1000000; int elapsed; while(1) { print("main loop test"); while(pass_number <= total_passes) { waitpeq(on_sensor, on_sensor); // Wait for on sensor high print("on_sensor test"); t_initial = CNT; waitpeq(off_sensor, off_sensor); // Wait for off sensor high print("off_sensor test"); t_final = CNT; total = total + (t_final - t_initial); // Accumulate time for total amount of passes(in ticks) pass_number++; } elapsed = (total * uS)/total_passes; // Calculate average pass time in uS print("Elapsed Time = %d\n", elapsed); pass_number = 0; total = 0; } }
This is the fidget spinner motor code so far. The motor runs, but I get no output from time_it on terminal.
The Flip and all magnet control hardware run on a LIPO battery pack. Is it a code problem or a power conflict
between the LIPO and the USB power when using terminal? It could also be an Apple problem since I have found
at least one incompatibility between Apple and Simple-IDE.
Comments
learn.parallax.com/tutorials/language/propeller-c/multicore-approaches/print-different-core
I have two Hall sensors oriented around a turning fidget spinner. One sensor is on_sensor, the other is off_sensor. time_it is meant to time the small area where one spinner weight passes on_sensor, and shortly after the next clockwise weight passes off_sensor. The output is close to what I expect; however, you can plainly see that the time alternates higher, lower, higher, lower, by about a millisecond or so. I think that the code is good. Could this variation be due to what the propeller hub does? I have 3 routines running in different hubs, but this one runs alone, or is not meant to interact with the others.
gives a negative number in its present form.
I know roughly what the problem is but don't fully understand, could you please help?