Tactile pressure sensor with Teensy 3.5 help

Status
Not open for further replies.

reeder13

New member
I have made my own tactile pressure sensor and and have got it to work using this code http://www.sensitronics.com/tutorials/fsr-matrix-array/page6.php and an arduino uno. The data is sent to processing where i have a nice visualization.

I am now trying to use a teensy 3.5 instead of the arduino uno. I have got some simpler code to work where its prints data into the serial monitor. Now i am trying to use the code above so i can get the visualization with the teensy. However with the teensy the visualization of the data in processing isn't correct. I was hoping someone could help me understand why the code would work for the arduino uno but not for the teensy. Additionally i had to comment out the following lines to get it to work with the teensy.

#ifndef cbi

#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))

#endif

#ifndef sbi

#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

#endif

.
.
.
.
.

sbi(ADCSRA,ADPS2); //set ADC prescaler to CLK/16

cbi(ADCSRA,ADPS1);

cbi(ADCSRA,ADPS0);
 
32 bit ARM .vs. 8 bit AVR and the value in use are perhaps behind the trouble. I've not used _SFR_BYTE / AVR Special function registers - I see it defined for Teensy3(ARM) - but only used in Teensy(2==AVR). Either there are better/alternate ways to address those register values (?) on T_3.5 - or if valid it is likely working with 32 bit value where AVR may have only pulled 8 bits?

If you can print the data sent to processing in a human readable form - perhaps in HEX - from both devices and compare you may see where the number of bits used, the values, or the order presented differs between the two to see where the error comes in.

The "#" hash tag icon on the reply command bar will allow code wrapping for better formatting.
 
These macro's are specific to the Arduino UNO.
Code:
#define SET_SR_DATA_HIGH()        PORTD|=B00000100
#define SET_SR_DATA_LOW()         PORTD&=~B00000100
#define SET_SR_CLK_HIGH()         PORTD|=B00001000
#define SET_SR_CLK_LOW()          PORTD&=~B00001000

On the linked web site, you can go back to step 3 and get the shiftColumn function that does not use these macro's.
 
This style of programming is very tightly tied to the AVR chip. Teensy 3.5 has some limited emulation support, so code like "PORTD &= ~B00000100" will work, but much of the rest will not work on any non-AVR processor.

For controlling the pins, using pinMode(pin, mode) and digitalWrite(pin, value). For the A/D, use analogRead(pin). These Arduino functions are well supported. They will allow your program to work on Teensy 3.5 and most other boards.

If you *really* want maximum speed, use digitalWriteFast(). But be warned, on Teensy 3.5 at 120 MHz, this can be far too fast for some uses. When you're running on AVR at only 16 MHz, each clock is 62 ns, so most operations taking a couple clocks create waveforms that work with most digital logic chips. But at 120 MHz, each clock is only 8.3 ns.
 
Status
Not open for further replies.
Back
Top