Diane and I (Marta) built our board with the 18f452 pic and a flex sensor. We went through several stages, including testing sensor reading in hyperterm. We modified the peak detection code to send raw values to processing. We also added a pause, to reduce the delay due to processings rendering delay. The code:
-- Marta Lwin
- initial test of 50 for threshold gave acceptable results
- initial test of 5 gave acceptable noise reduction in resulting DataLogger graph
This code sent its serial output to Tom's Simple serial Datalogger. Resulting DataLogger graph returned results representational of sensor event in real-time.
' Define ADCIN parameters DEFINE ADC_BITS 10 ' Set number of bits in result DEFINE ADC_CLOCK 3 ' Set clock source (3=rc) DEFINE ADC_SAMPLEUS 20 ' Set sampling time in uS PeakValue var word SensorValue var word LastSensorValue var word Threshold var word Noise var word ' serial pins and data reate: tx var portc.6 rx var portc.7 n9600 con 16468 Threshold = 50 ' set your own value based on your sensors PeakValue = 0 ' initialize peakValue noise = 5 ' set a noise value based on your particular sensor ' Set PORTA to all input TRISA = %11111111 ' Set up ADCON1 ADCON1 = %10000010 Main: ' read sensor on pin RA0: ADCin 0, sensorValue serout2 tx, n9600, [sensorValue] 'original line was useful when sending data to HyperTerminal. 'original line: serout2 tx, n9600, ["peak reading", DEC peakValue, 13,10] pause 100 Goto main