We are trying to generate via code a sawtooth waveform and output a graph of it to the logic analyzer. The calculations for the sawtooth equation are more or less done. We just don't know how to use a gpio analog port to display it on the logic analyzer.
This is the code:
void sawtooth (void const *argument) { float amplitude; // peak-to-peak amplitude float frequency; // output frequency in Hz float offset; // amplitude offset float duration; // duration in Seconds float val; int state; osEvent result; for(;;) { result = osSignalWait (0x00,0); switch(result.value.v) { case 1: SendText("Running sawtooth \n\n"); state = 1; break; case 2: state = 2; break; default: break; } switch(state) { case 1: //Code for waveform generation goes here osThreadSetPriority(T_uartThread, osPriorityHigh); break; case 2: break; default: break; } } }
We are aware that the following code exists on Keil's website but it does not work on the board we are required to use.
/*---------------------------------------------------*/ /* Generate Sawtooth Signal on AD Channel 1 */ /*---------------------------------------------------*/ // SIGNAL void AIN1_Saw (void) { float volts; // peak-to-peak volatage float frequency; // output frequency in Hz float offset; // volatge offset float duration; // duration in Seconds float val; long i, end, steps; volts = 2.0; offset = 0.2; frequency = 1400; duration = 0.2; printf ("Sawtooth Signal on AD Channel 1.\n"); steps = (100000 * (1/frequency)); end = (duration * 100000); for (i = 0 ; i < end; i++) { val = (i % steps) / ((float) steps); AIN1 = (val * volts) + offset; swatch (0.00001); // in 10 uSec increments } } DEFINE BUTTON "AIN1 Saw","AIN1_Saw()"