- Posts: 752
- Thank you received: 0
IO interface with Arduino over Ethernet
Regards
Marius
www.bluearccnc.com
Please Log in to join the conversation.
- DocStein99
- Offline
- Junior Member
-
- Posts: 30
- Thank you received: 0
M4MazakUser wrote: Im looking at ordering a stm32f103c8t6 and a enc28j60 network adapter to see how much speed i can get for encoder counting... The arm cortex-m3 runs at 72mhz and it looks like it can be programmed from the arduino ide. I'll let you know how i go.
That's obviously much faster than the Uno or Nano boards I'm testing with. Are you using the encoders for position feedback?
Please Log in to join the conversation.
- DocStein99
- Offline
- Junior Member
-
- Posts: 30
- Thank you received: 0
mariusl wrote: Also look at the System Workbench for STM32. It's an Eclipse based IDE for STM. Very powerful environment. The Arduino framework is limited and most developed for the F103 so you might have some success. It is still very green though.
It's all the libraries and example support I rely on for Arduino, that helps me to learn and get a project done.
Please Log in to join the conversation.
- M4MazakUser
- Offline
- Premium Member
-
- Posts: 149
- Thank you received: 0
Please Log in to join the conversation.
- DocStein99
- Offline
- Junior Member
-
- Posts: 30
- Thank you received: 0
There is a latency in the transmission of the data between the Linux box and my Arduino, definately enough time to foul up positioning, if I were to use parallel pins local and expect position feedback through an network.
Do you plan also to send the step & direction pulses through the network as well? If that's the case - the packets would have to travel to the module through the network latency - then be even more latent to receive the encoder feedback. The module would need a complicated algorithm to work. At that point, the module is pretty much driving the motion, instead of HAL.
Please Log in to join the conversation.
- M4MazakUser
- Offline
- Premium Member
-
- Posts: 149
- Thank you received: 0
Please Log in to join the conversation.
- M4MazakUser
- Offline
- Premium Member
-
- Posts: 149
- Thank you received: 0
example as follows. -using arduino ide
/*
* Hardware Timer as an Encoder interface.
*
* The STM32 Timers have the possibility of being used as an encoder interface.
* This can be both a quadrature encoder (mode 3) or pulse encoder with a signal to give direction (modes 1 and 2).
* The default behavior is for quadrature encoder.
*
* To avoid overflowing the encoder (which may or may not happen (although with 16 bits, it's likely), the following code
* will interrupt every time the number of pulses that each revolution gives to increment/decrement a variable (ints).
*
* This means that the total number of pulses given by the encoder will be (ints * PPR) + timer.getCount()
*
* To test this library, make the connections as below:
*
* TIMER2 inputs
* D2
* D3
*
* COUNTING DIRECTION:
* 0 means that it is upcounting, meaning that Channel A is leading Channel B
*
* EDGE COUNTING:
*
* mode 1 - only counts pulses on channel B
* mode 2 - only counts pulses on Channel A
* mode 3 - counts on both channels.
*
*/
#include "HardwareTimer.h"
//Encoder stuff
//Pulses per revolution
#define PPR 1024
HardwareTimer timer(2);
unsigned long ints = 0;
void func(){
if (timer.getDirection()){
ints--;
} else{
ints++;
}
}
void setup() {
//define the Timer channels as inputs.
pinMode(D2, INPUT_PULLUP); //channel A
pinMode(D3, INPUT_PULLUP); //channel B
//configure timer as encoder
timer.setMode(0, TIMER_ENCODER); //set mode, the channel is not used when in this mode.
timer.pause(); //stop...
timer.setPrescaleFactor(1); //normal for encoder to have the lowest or no prescaler.
timer.setOverflow(PPR); //use this to match the number of pulse per revolution of the encoder. Most industrial use 1024 single channel steps.
timer.setCount(0); //reset the counter.
timer.setEdgeCounting(TIMER_SMCR_SMS_ENCODER3); //or TIMER_SMCR_SMS_ENCODER1 or TIMER_SMCR_SMS_ENCODER2. This uses both channels to count and ascertain direction.
timer.attachInterrupt(0, func); //channel doesn't mean much here either.
timer.resume(); //start the encoder...
}
//Support variables.
unsigned long interval=0; //variable for status updates...
char received = 0;
void loop() {
//encoder code
if (millis() - interval >= 1000) {
Serial.print(timer.getCount());
Serial.println(" counts");
Serial.print("direction ");
Serial.println(timer.getDirection());
Serial.print("Full Revs: ");
Serial.println(ints);
interval = millis(); //update interval for user.
}
}
this shows a lot of promise.
Please Log in to join the conversation.
- DocStein99
- Offline
- Junior Member
-
- Posts: 30
- Thank you received: 0
Please Log in to join the conversation.
- cromaglious
- Offline
- New Member
-
- Posts: 7
- Thank you received: 0
You sir, are a god! I've taken your code and ported it to the Arduino MEGA2560. I was able to get 24 pins for digital output, 10 pins for PWM output. 16 pins for digital input, and a further 6 pins being read by interrupts.
Using binary for data I was able to get the packet size down to 14bytes for receive to the Arduino and 3 bytes for the return packet. the packet size will grow a bit more when I get the serial communication working. pins 14,15,16,17 for serial. I'm using the analog pins as digitals, though I might make 8 pins analog in the future. Which would grow the send packet grow by 11 bytes 12bits per pin.. is a byte and a nibble. So I save a byte on the digital pins, and grow 12 bytes for the 8 12bits adc values.
// evens
byte wbuf[12];
for(i=0; i<8; i=i+2) { tbuf=analogRead(i); wbuf[i+ANALOGDATA]=char(tbuf & B11111111); wbuf[(i/2)+8]=char(tbuf>>
//odds
for(i=1; i<8; i=i+2) { tbuf=analogRead(i); wbuf[i+ANALOGDATA]=char(tbuf & B11111111); wbuf[(i-1)/2+8]|=(tbuf>>4)&B11110000 ;}
having an issue with gwibber
my code isn't working at the second...
Please Log in to join the conversation.
- DocStein99
- Offline
- Junior Member
-
- Posts: 30
- Thank you received: 0
Please Log in to join the conversation.
