Ethernet Problem When Changing PWM Frequency

I'm having trouble getting ethernet responses whenI change the PWM frequency divisor to 1024. I use the code from Timer1 example on Ardino site. My setup is as follows:

Arduino Nano 3.0 w/Wiznet 811MJ

PWM Pins Changed = 5 and 6 to Divisor 1024

Ethernet Pins: 09 - Reset 10 - SCS 11 - MOSI 12 - MISO 13 - SCLK

Does changing these PWM frequencies affect the response time of the Ethernet data. To resolve this, do I have to edit the Ethernet.h files, or do I need to change my Windows host application code to allow more time for the ethernet response?

Thank you for your help.

What Timer1 example exactly? Can you post it please? Use code tags.

Before I do that, let me just as a question:

I'm actually using Timer0 of the Arduino. I understand that changing the frequency divisor affects the millis() and delay() functions.

My question is:

Does changing the frequency divisor of Timer 0 from its default have any effect on the operation of the Ethernet libraries?

Thanks.

The answer to your question is a yes and no. I cannot find any direct relation between the Timer0 and the W5100 or Ethernet code (the SPI uses a separate frequency divider and is not depending on the prescaler unit). If you are using any of the utility code (EthernetClient, Dhcp or DNS) though, they use calls to millis() for timing issues and a changed prescaler setting of Timer0 will affect their behavior.

BTW: In your first message you wrote about Timer1, in the second about Timer0. Although they use the same prescaler unit, the prescaler values are different for Timer0 and Timer1.

renniejohnson:
My question is:

Does changing the frequency divisor of Timer 0 from its default have any effect on the operation of the Ethernet libraries?

Well let’s see if delay or millis is used …

$ cd /Applications/Arduino\ 1.0.app/Contents/Resources/Java/libraries/Ethernet/
$ grep -i delay *.cpp

Dhcp.cpp:        delay(50);
Dns.cpp:        delay(50);
EthernetClient.cpp:    delay(1);
EthernetClient.cpp:    delay(1);

$ grep -i millis *.cpp

Dhcp.cpp:    unsigned long startTime = millis();
Dhcp.cpp:            send_DHCP_MESSAGE(DHCP_DISCOVER, ((millis() - startTime) / 1000));
Dhcp.cpp:                send_DHCP_MESSAGE(DHCP_REQUEST, ((millis() - startTime) / 1000));
Dhcp.cpp:        if(result != 1 && ((millis() - startTime) > timeout))
Dhcp.cpp:    unsigned long startTime = millis();
Dhcp.cpp:        if((millis() - startTime) > responseTimeout)
Dns.cpp:    if (iUdp.begin(1024+(millis() & 0xF)) == 1)
Dns.cpp:    iRequestId = millis(); // generate a random ID
Dns.cpp:    uint32_t startTime = millis();
Dns.cpp:        if((millis() - startTime) > aTimeout)
EthernetClient.cpp:  unsigned long start = millis();
EthernetClient.cpp:  while (status() != SnSR::CLOSED && millis() - start < 1000)

$ cd utility
$ grep -i delay *.cpp

w5100.cpp:  delay(300);

So yes, I would say that changing the behaviour of timer 0 would affect the Ethernet library.

Thank you friends.

Do you think I can modify the ethernet library to support the frequency change, or should I user a different timer for my PWM needs?. I only need two channels for DC motor control. Otherwise, I’ll have to change the circuit board design to use a different timer for PWM.

Thanks again.

In software, the simplest change would be to re-arrange the hardware.

If that's a big issue and (say) Timer 2 is free you could probably simply change the core of millis() and micros() top use Timer 2 rather than Timer 0.

Or keep Timer 0 and change internally what millis(), micros() and delay() does. So if the time reported is 2x the original time, just halve it before returning it.

Nick, that's a great idea. Offhand, do you know which library file contains these functions? I wonder if I can override the functions. It seems that C++ works a little funky with Arduino IDE. I've never tried to do inheritance.

They are in wiring.c ... just search for that in the core distribution folders. You can't inherit from it, they are C functions not C++ ones.

You would have to modify them in situ.

If you don't want that modification for all your projects just make a copy of the entire IDE and use the modified one for this project.

OK, this is awsome! So,if I make a copy of wiring.c/wiring.h and put it in my arduino sketch folder, will the compiler use it and stop searching for that file, or do I have to put the whole stinking ethernet core ide in the sketch folder?

So,if I make a copy of wiring.c/wiring.h and put it in my arduino sketch folder, will the compiler use it ...

I doubt it, but you could try.