Changing the ISP speed on teensy 3.6 for wiz5100

Status
Not open for further replies.

Tady

Well-known member
Hello i have a small project that controlls some motors and i am using a webserver to adjust settings...
Everything was working well on arduino mega2560, but now i have ported everything to teensy 3.6 (need processing power).
If i program the teensy to work with anything above 120MHz the shield stops responding. I measured the clock frequency and at ~6MHz clock speed the shiels works.. Anything above doesn't work.. At 180MHz the webpage is shown but not complete.. The style is missing and the input boxes al all around the page...
Anyway i was searching google and forums for a simple way to change the clock divider.. How can i accomplish this?
Thank you!
 
Hi,

If you mean the SPI clock, find this file in your Arduino installation and change line 17.

https://github.com/PaulStoffregen/Ethernet/blob/master/w5100.h

Also - Paul's recent commits to the Ethernet library seem to assume there will always be a hardware reset IC on the wiznet IC reset pin which broke a lot of my wiznet boards, so you may need this code inside setup()

pinMode(9, OUTPUT);
digitalWrite(9, LOW); // reset the WIZ820io
delay(100);
digitalWrite(9, HIGH); // release the WIZ820io
 
Last edited:
Thank you for your help! I think i found out what the problem was! The shield is designed to work with an Arduino but i connected it to the teensy. I connected miso mosi clk and chip select... But i forgot the reset line:)))
How can you damage a board without toggling the line? I don't have that piece of code and it works without problems?:) but i do have a line Ethernet.init(10); 10 is my chip select so maybe Paul updated the code that includes this :)
 
well the reset pin always needs to be tied high if not being controlled by gpio in order for most hardware to work, otherwise the registers get reset because of the floating reset line
 
Several different ethernet shields have been made for regular Arduino boards. Some have better hardware design than others. Without knowing which specific hardware you have, here's some of the known issues...

The older Wiznet chips need a reset pulse. W5500 seems to work if reset is just connected high. But W5100 and W5200 have trouble if reset doesn't pulse low before you use the chip. Even if you have a pullup resistor or Vcc connection for reset, these chips can fail to work properly if they don't receive a low pulse at some point before you use them. It's simply how the chips are made.

The newer Arduino ethernet shields and the PJRC adaptor for WIZ820io & WIZ850io have a CAT811 chip which always gives the Wiznet chip a reliable reset pulse.

Some very old shields may depend on the reset pin from Arduino Uno & Mega, which the 16u2 or FTDI chip pulses low when you upload code. Some shields may not even have a pullup resistor on that pin, so they don't even work at all when used on boards which don't have a reset signal. These older shields are very unreliable, even with Arduino Uno.

Most of the shields on the market also lack pullup resistors on the chip select signals, which can cause trouble if you have a SD card in their socket and you use Ethernet.begin() before SD.begin(). The SD card can "hear" the ethernet communication if its chip select pin happens to float low. The solution is just driving the CS pins high with either pinMode INPUT_PULLUP or digitalWrite HIGH before you use either library.
 
Hmm... Thank you for your replyes! The cip is W5100 i don't know the exact board. It's a clone.

I tied the reset pin to a GPIO and just before the Ethernet.init and begin i drive the reset line low and high (100ms delay) the sd card is not in the shield but in the teensy.
I made a webpage and on that webpage I can change IP,subnet,gateway,username,password, UDP port and other parameters that control some DC servo motors (PIDs) . I made the program so if you change any of the ethernet setting the teensy reboots. I didn't know how to do that so i cheated and used the watchdog timer. If I change any of the settings the program gets stuck in a while loop.
I was a bit sceptical but it works perfectly!
After i built the reset mechanism i saw i have problems sometimes. So i mad the reset line go low and high.
No problems after this :)
Thank you!
 
i just bought a WIZ820io board. Man WHAT A DIFFERENCE :) but i still don't know how to change the SPI clock speed :/ it always runs at 4MHz ...
Does any one have problems with UDP? mine seems to stop recieving data after a while. I can't post the code (4000 lines long). I'ts not a big problem but if someone has any experience of guidelines it would be helpful :)
 
but i still don't know how to change the SPI clock speed :/ it always runs at 4MHz ...

Did you actually measure the SPI clock, or is based only on reviewing the code?

Teensyduino's version of the Ethernet library uses faster SPI clock. It has several other optimizations not (yet) found in Arduino's version. The code is vastly different between Teensy & Arduino (but hopefully Arduino will soon adopt Teensy's improved version), so make sure you are looking at the correct version of the library!

Faster SPI clock speed will only improve Ethernet's speed if used on a LAN. If you have any significant network latency, the throughput will be limited with the small buffers of the Wiznet chip. Fast SPI will mean the Ethernet library spends less CPU time, but that only does you any good if your code attempts to do other tasks instead of just waiting in a loop to send or receive data.

If you want to tune this stuff, you can. Just make sure you're editing the right copy of Ethernet. Turn on verbose info while compiling in File > Preferences. Then Arduino will show you the full pathname of the libraries it's actually using. In Teensyduino's version, look for this in w5100.h.

Code:
// Safe for all chips
#define SPI_ETHERNET_SETTINGS SPISettings(14000000, MSBFIRST, SPI_MODE0)

// Safe for W5200 and W5500, but too fast for W5100
// uncomment this if you know you'll never need W5100 support
//#define SPI_ETHERNET_SETTINGS SPISettings(30000000, MSBFIRST, SPI_MODE0)

To change the buffer sizes, look for this in w5100.cpp:

Code:
//#define W5500_4K_BUFFERS
//#define W5200_4K_BUFFERS

If you're communicating over the internet, these buffer sizes are the setting that matters. Faster SPI will cause the library to use less CPU time, but that only means your code gets to wait longer.
 
I connected an oscilloscope to the clock pin and it is 4MHz. And yes i need the CPU time to run PIDs. I get data trough UDP and i control some servo motors. And yes the compiler uses the library found in teensy dir and i installed the latest teendyduino. Thank you for helping me. I will try this in the morning.

Thank you!
 
I tried just now, running the WebClient example on Teensy 3.6 with a WIZ820io module.

My oscilloscope disagrees with you. It says the SPI clock is 12 MHz.

file.png
(click for full size)
 
Maybe you're somehow using Arduino's version of the library? If you've installed a copy in the sketchbook libraries folder, it's probably overriding all others. Turn on verbose info and look at the summary it prints about which libraries were really used. The Teensyduino one is in hardware/teensy/avr/libraries/Ethernet.

The SPI clock is only a small part of the optimization. Teensyduino's version also has caching of the socket state, which dramatically reduces the amount of SPI communication needed. It can make a huge performance difference.
 
Status
Not open for further replies.
Back
Top