wbcapri
Posts: 1
Joined: Tue Aug 20, 2013 11:01 am

Re: LinuxCNC

Tue Aug 20, 2013 11:39 am

Hello, I would like to know how I can connect to picnc dsPIC-servo controller described on page
http://members.shaw.ca/swstuff/dspic-servo.html

Regards
wbcapri

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Tue Aug 20, 2013 3:00 pm

wbcapri wrote:Hello, I would like to know how I can connect to picnc dsPIC-servo controller described on page
http://members.shaw.ca/swstuff/dspic-servo.html

Regards
wbcapri
Hi,

The picnc firmware needs to be modified to output a quadrature signal on the step and dir pins. This should be a trivial change as the code already exists and it only needs to be ported to PIC32.

Cheers!
42

siamect
Posts: 8
Joined: Thu Sep 12, 2013 1:57 pm

Re: LinuxCNC

Thu Sep 12, 2013 5:45 pm

I have a max32 board and I thought it would be a good idea to use avrdude from the command line to get the picnc.hex file into the PIC processor...
I have done it with other hex files (generated by the mpide) and it works but for some reason I get segfault when avrdude starts reading the picnc.hex file. I also tried with the picnc_bb.hex file with the same result.
Does anyone else have this problem? Is there anything special with these hex files?

Code: Select all

martin@martin-GX60-1AC:~/Documents/picnc/firmware/PICnc$ avrdude -P /dev/ttyUSB0 -p pic32  -b 115200 -c stk500v2 -v -v -U flash:w:picnc.hex 

avrdude: Version 5.11, compiled on Sep  7 2011 at 19:34:16
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/usr/local/etc/avrdude.conf"
         User configuration file is "/home/martin/.avrduderc"

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : stk500v2
         Overriding Baud Rate          : 115200
avrdude: ser_recv(): programmer is not responding
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_recv(): programmer is not responding
avrdude: stk500v2_ReceiveMessage(): timeout
         AVR Part                      : 32MX795F512H
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    10     4    0 no       2048    8      0  9000  9000 0xff 0xff
           flash         65    10   128    0 yes    524288  256   2048  4500  4500 0xff 0xff
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : STK500V2
         Description     : Atmel STK500 Version 2.x firmware
         Programmer Model: AVRISP
         Hardware Version: 15
         Firmware Version Master : 2.10
         Vtarget         : 0.0 V
         SCK period      : 276.7 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.12s

avrdude: Device signature = 0x504943
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: current erase-rewrite cycle count is -1145324613 (if being tracked)
avrdude: erasing chip
avrdude: reading input file "picnc.hex"
avrdude: input file picnc.hex auto detected as Intel Hex
Segmentation fault (core dumped)


kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Fri Sep 13, 2013 3:19 am

Hi,

This is normal as the bootloader is not being used.

I'll update later on how to modify for mpide. The original development was actually done on a chipkit.

Cheers!
42

siamect
Posts: 8
Joined: Thu Sep 12, 2013 1:57 pm

Re: LinuxCNC

Fri Sep 13, 2013 11:59 am

Thanks a million!

hybris
Posts: 52
Joined: Mon Jun 03, 2013 8:50 pm
Location: Tyrol / Austria

Re: LinuxCNC

Fri Sep 13, 2013 12:29 pm

hey kinsa

next step, next problem :?
sorry, we couldn't solve the problems on our own!

first: we've tried to install the spi driver for the raspberry, i think that worked (with your instructions from the test driver readme, but adjusted for the picnc_jr)
next we searched in the sample-configs for a .hal file, which is already modified for the raspberry. is there one or should we modify one?

second: tried to compile the picnc jr files, but i'm getting an error. these files are the same that you used, aren't they?
so maybe i'm using the wrong compiler?

Code: Select all

tom@ubuntu:~/picnc/firmware/PICnc_Jr$ make
/opt/microchip/xc32/v1.21/bin/xc32-gcc -EL -g -mips32r2 -mprocessor=32MX150F128B -O3 -Wextra -Wall -fno-exceptions -ffunction-sections -fdata-sections -mno-smart-io  -O -I. -I. -MT main.o -MD -MP -MF .deps/main.dep   -c -o main.o main.c
In file included from main.c:24:0:
stepgen.h:37:2: error: expected specifier-qualifier-list before 'int32_t'
main.c:50:26: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rxBuf'
main.c: In function 'init_dma':
main.c:132:57: error: 'rxBuf' undeclared (first use in this function)
main.c:132:57: note: each undeclared identifier is reported only once for each function it appears in
main.c:133:39: error: 'txBuf' undeclared (first use in this function)
main.c: In function 'main':
main.c:152:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'x'
main.c:152:18: error: 'x' undeclared (first use in this function)
main.c:191:34: error: 'txBuf' undeclared (first use in this function)
main.c:194:15: error: 'rxBuf' undeclared (first use in this function)
make: *** [main.o] Error 1
sorry for getting on your nerves ;) and thanks a lot
Tom

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Fri Sep 13, 2013 12:40 pm

Attached is the modified Makefile for max32 (if your chip uses PIC32MX795F512L). Modify GCCPREFIX, DEVICE, AVRDUDE and AVRDUDECONF to the correct values.

Make sure to use the PICnc version when you want to modify the code. Included is the test firmware and the modified hardware.h

Do note I haven't tested this on a real hardware though. If it works, the led should blink.

Cheers!
Attachments
picnc.zip
(7.78 KiB) Downloaded 387 times
42

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Fri Sep 13, 2013 12:54 pm

hybris wrote:hey kinsa

next step, next problem :?
sorry, we couldn't solve the problems on our own!

first: we've tried to install the spi driver for the raspberry, i think that worked (with your instructions from the test driver readme, but adjusted for the picnc_jr)
next we searched in the sample-configs for a .hal file, which is already modified for the raspberry. is there one or should we modify one?

second: tried to compile the picnc jr files, but i'm getting an error. these files are the same that you used, aren't they?
so maybe i'm using the wrong compiler?

Code: Select all

tom@ubuntu:~/picnc/firmware/PICnc_Jr$ make
/opt/microchip/xc32/v1.21/bin/xc32-gcc -EL -g -mips32r2 -mprocessor=32MX150F128B -O3 -Wextra -Wall -fno-exceptions -ffunction-sections -fdata-sections -mno-smart-io  -O -I. -I. -MT main.o -MD -MP -MF .deps/main.dep   -c -o main.o main.c
In file included from main.c:24:0:
stepgen.h:37:2: error: expected specifier-qualifier-list before 'int32_t'
main.c:50:26: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rxBuf'
main.c: In function 'init_dma':
main.c:132:57: error: 'rxBuf' undeclared (first use in this function)
main.c:132:57: note: each undeclared identifier is reported only once for each function it appears in
main.c:133:39: error: 'txBuf' undeclared (first use in this function)
main.c: In function 'main':
main.c:152:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'x'
main.c:152:18: error: 'x' undeclared (first use in this function)
main.c:191:34: error: 'txBuf' undeclared (first use in this function)
main.c:194:15: error: 'rxBuf' undeclared (first use in this function)
make: *** [main.o] Error 1
sorry for getting on your nerves ;) and thanks a lot
Tom
You don't need kernel SPI driver, it needs to be unloaded before using the hal driver.

Compiling the firmware needs the mpide compiler. The instructions for compiling are detailed here: https://code.google.com/p/picnc/wiki/CompilingFirmware

I'm not sure why the test commands were not uploaded to the server but here are the halrun commands for testing:

Code: Select all

loadrt threads name1=test period1=1000000
loadrt siggen
loadrt hal_picnc_jr

net X-vel siggen.0.cosine => picnc-jr.0.velocity-cmd
net Y-vel siggen.0.sine => picnc-jr.1.velocity-cmd
net Z-vel siggen.0.sawtooth => picnc-jr.2.velocity-cmd
net A-vel siggen.0.triangle => picnc-jr.3.velocity-cmd
setp picnc-jr.0.maxaccel 1
setp picnc-jr.0.maxvel 2
setp picnc-jr.0.scale 10000
setp picnc-jr.1.maxaccel 1
setp picnc-jr.1.maxvel 2
setp picnc-jr.1.scale 10000
setp picnc-jr.2.maxaccel 1
setp picnc-jr.2.maxvel 2
setp picnc-jr.2.scale 10000
setp picnc-jr.3.maxaccel 1
setp picnc-jr.3.maxvel 2
setp picnc-jr.3.scale 10000
setp picnc-jr.3.enable 1
setp picnc-jr.0.enable 1
setp picnc-jr.1.enable 1
setp picnc-jr.2.enable 1
setp picnc-jr.3.enable 1

setp siggen.0.amplitude 2
setp siggen.0.frequency .1

addf picnc-jr.read-spi test
addf siggen.0.update test
addf picnc-jr.stepgen test
addf picnc-jr.write-spi test
start
This should generate some signals on the step/dir pins.

I really need to clean up the code as there are too many versions around. I just don't have enough play time as I'm busy with work :)

I'm happy to help, just let me know when you are stuck.

Cheers!

PS. Here is a working config for my mill: https://code.google.com/p/picnc/source/ ... igs%2FMF70
42

siamect
Posts: 8
Joined: Thu Sep 12, 2013 1:57 pm

Re: LinuxCNC

Fri Sep 13, 2013 4:42 pm

Great! The LED is "blinking" so it looks ok but I have not tested anything.
Thanks a lot!
The build process generated some errors but it seemed ok at the end? At least the hex file was generated.

Code: Select all

BFD: Dwarf Error: Can't find .debug_line section.
BFD: Dwarf Error: Can't find .debug_line section.
I modified the Makefile a little more to suit my taste...
My avrdude is in my path already and the conf file is /usr/local/etc/avrdude.conf
I usually also have this -U flash:w<filename> thing that I assume should be there for some reason... guess it is to write in the flash :?:

Code: Select all

AVRDUDE = avrdude
AVRDUDECONF =  -c stk500v2 \
		-p pic32 -P /dev/ttyUSB0 -U flash:w:
and the second of these lines to get rid of the space before the file name...

Code: Select all

load:           .deps picnc.elf
		$(AVRDUDE) $(AVRDUDECONF)picnc.hex
Many thanks...

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Sat Sep 14, 2013 12:27 am

The error is normal, it is just complaining about the missing debug section in the output.

I've changed the code to use channel 1 for SPI as channel 2 is used by the usb uart.
42

hybris
Posts: 52
Joined: Mon Jun 03, 2013 8:50 pm
Location: Tyrol / Austria

Re: LinuxCNC

Sat Sep 14, 2013 11:24 am

kinsa wrote:
Compiling the firmware needs the mpide compiler. The instructions for compiling are detailed here: https://code.google.com/p/picnc/wiki/CompilingFirmware
thanks, didn't realize that you've already posted a instruction for compiling, with this compiler everything worked :)
kinsa wrote: You don't need kernel SPI driver, it needs to be unloaded before using the hal driver.

I'm not sure why the test commands were not uploaded to the server but here are the halrun commands for testing:


This should generate some signals on the step/dir pins.
sorry, i meant to write "hal driver"
i did:

Code: Select all

sudo ln -s /usr/local/include/linuxcnc/ /usr/local/include/userpci
sudo comp --install hal_picnc_jr.comp
sudo rmmod spi_bcm2708
sudo halrun
then i tested the step/dir signals with your commands, but i didn't get the right signals, it more looks like signal noise :?
is there a possibility to check first the raspberry output?

thanks a lot :)
greets

siamect
Posts: 8
Joined: Thu Sep 12, 2013 1:57 pm

Re: LinuxCNC

Sat Sep 14, 2013 11:26 am

Hmm, maybe I'm missing something. I look in the schematics http://www.digilentinc.com/Data/Product ... _d_sch.pdf
It looks like the U1ARX and U1ATX is connected to the USB circuit and the SDI2A, SDO2A and SCK2A is connected to J13 via the JP3, JP4.
Doesn’t this mean we should use SPI2 (channel 2 ?) on the ChipKit MAX32 board?
Best regards
Martin

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Sat Sep 14, 2013 11:33 am

hybris wrote:
kinsa wrote:
Compiling the firmware needs the mpide compiler. The instructions for compiling are detailed here: https://code.google.com/p/picnc/wiki/CompilingFirmware
thanks, didn't realize that you've already posted a instruction for compiling, with this compiler everything worked :)
kinsa wrote: You don't need kernel SPI driver, it needs to be unloaded before using the hal driver.

I'm not sure why the test commands were not uploaded to the server but here are the halrun commands for testing:


This should generate some signals on the step/dir pins.
sorry, i meant to write "hal driver"
i did:

Code: Select all

sudo ln -s /usr/local/include/linuxcnc/ /usr/local/include/userpci
sudo comp --install hal_picnc_jr.comp
sudo rmmod spi_bcm2708
sudo halrun
then i tested the step/dir signals with your commands, but i didn't get the right signals, it more looks like signal noise :?
is there a possibility to check first the raspberry output?

thanks a lot :)
greets
Could you post your modifications?
42

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Sat Sep 14, 2013 11:39 am

siamect wrote:Hmm, maybe I'm missing something. I look in the schematics http://www.digilentinc.com/Data/Product ... _d_sch.pdf
It looks like the U1ARX and U1ATX is connected to the USB circuit and the SDI2A, SDO2A and SCK2A is connected to J13 via the JP3, JP4.
Doesn’t this mean we should use SPI2 (channel 2 ?) on the ChipKit MAX32 board?
Best regards
Martin
Yup, you're right :) I was looking at SCL2/SDA2.

Just change the spi channel in hardware.h

Cheers!
42

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Sat Sep 14, 2013 11:49 am

hybris wrote: sorry, i meant to write "hal driver"
i did:

Code: Select all

sudo ln -s /usr/local/include/linuxcnc/ /usr/local/include/userpci
sudo comp --install hal_picnc_jr.comp
sudo rmmod spi_bcm2708
sudo halrun
Please try this:

Code: Select all

sudo rmmod spi_bcm2708
sudo halrun
loadrt threads name1=test period1=1000000
loadrt hal_picnc_jr

setp picnc-jr.0.maxaccel 1
setp picnc-jr.0.maxvel 2
setp picnc-jr.0.scale 1000
setp picnc-jr.0.enable 1

addf picnc-jr.read-spi test
addf picnc-jr.stepgen test
addf picnc-jr.write-spi test
start

setp picnc-jr.0.velocity-cmd 1
This will generate pulses on the step pin of axis 0.

Play with the velocity-cmd values. Setting this value to less than 0 should toggle the dir pin.

Let me know how it goes.
42

hybris
Posts: 52
Joined: Mon Jun 03, 2013 8:50 pm
Location: Tyrol / Austria

Re: LinuxCNC

Sat Sep 14, 2013 2:09 pm

axis 0 is the x axis, isn't it?
your commands doesn't have an effect on the dir pin :(

modification, do you mean my circuit?

greets and thanks for your help :)

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Sat Sep 14, 2013 2:20 pm

hybris wrote:axis 0 is the x axis, isn't it?
your commands doesn't have an effect on the dir pin :(

modification, do you mean my circuit?

greets and thanks for your help :)
axis 0 = x axis

I need to see your circuit and code modifications.

try running the following commands to see if the values change after starting:

Code: Select all

show picnc-jr.0.counts
show picnc-jr.0.position-fb
or run the following and see if there are any activity:

Code: Select all

loadusr halmeter
42

hybris
Posts: 52
Joined: Mon Jun 03, 2013 8:50 pm
Location: Tyrol / Austria

Re: LinuxCNC

Sat Sep 14, 2013 3:39 pm

kinsa wrote: try running the following commands to see if the values change after starting:

Code: Select all

show picnc-jr.0.counts
show picnc-jr.0.position-fb
kinsa wrote: or run the following and see if there are any activity:

Code: Select all

loadusr halmeter

Code: Select all

loadusr halmeter
Xlib: extension "RANDR" missing on display ":10:0".
it starts anyways, picnc-jr.0.counts -> 0, picnc-jr.0.position-fb -> 0, but picnc-jr.0.velocity-cmd -> 1
picnc-jr.0.enable TRUE

my circuit:
circuit

i'm working with this image:
http://www.raspberrypi.org/phpBB3/viewt ... 82#p354382

think i haven't modified it yet, and the pic32 is flashed with the hex file based on the files on google code (firmware -> picnc_jr)

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Sat Sep 14, 2013 11:25 pm

hybris wrote: my circuit:
circuit
Is this correct, pin 1 of U2 is not connected to pin 1 of J1?

It should be connected.
42

hybris
Posts: 52
Joined: Mon Jun 03, 2013 8:50 pm
Location: Tyrol / Austria

Re: LinuxCNC

Sun Sep 15, 2013 12:18 pm

oh sorry, i've noticed it after i made my board. i fixed it already, i should have said that befor.
is it possible to check the signals on the mosi, miso, sclk or the txd, rxd pins?

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Sun Sep 15, 2013 12:36 pm

There is no easy way to check. You'll need a scope to see if there is activity on the bus.

Also, take note of the blinking rate of the led. The rate will increase once there is activity on the SPI pins. This will happen once the hal driver is loaded and started.

Can you please post the output of "show all" command from halrun?

Have you checked the output directly from the PIC32 pins?
42

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Sun Sep 15, 2013 1:02 pm

hybris wrote:oh sorry, i've noticed it after i made my board. i fixed it already, i should have said that befor.
is it possible to check the signals on the mosi, miso, sclk or the txd, rxd pins?
Please check pin 25 of U2 if you see any activity before and after running halcmd.

I haven't updated the PICnc Jr to the latest version. I've fixed a couple of bugs on the breadboard version, I'll try to update it this week.

Cheers!
42

hybris
Posts: 52
Joined: Mon Jun 03, 2013 8:50 pm
Location: Tyrol / Austria

Re: LinuxCNC

Sun Sep 15, 2013 1:29 pm

i've got a scope, just don't know how the signal should look like :)

befor and after running halrun, the blinking rate doesn't change :?

"show all" results
halrun.png
halrun.png (43.67 KiB) Viewed 7746 times
i've checked the output directly on the pic32 and on the print terminal
Please check pin 25 of U2 if you see any activity before and after running halcmd.
i'll check it
I haven't updated the PICnc Jr to the latest version. I've fixed a couple of bugs on the breadboard version, I'll try to update it this week.
thanks a lot! :)

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Sun Sep 15, 2013 2:07 pm

hybris wrote:axis 0 is the x axis, isn't it?
your commands doesn't have an effect on the dir pin :(

modification, do you mean my circuit?

greets and thanks for your help :)
Can you confirm that this is the correct pin assignment of your setup?

Code: Select all

/*    PORT USAGE
 *
 *   Pin Port  Dir   Signal
 *
 *   9   RA2   OUT   OUTPUT 0
 *   10  RA3   OUT   OUTPUT 1
 *   4   RB0   OUT   DATA
 *   5   RB1   OUT   MISO
 *   14  RB5   OUT   Status LED
 *   15  RB6   OUT   DIR_A
 *   16  RB7   OUT   STEP_A
 *   17  RB8   OUT   DIR_Z
 *   18  RB9   OUT   STEP_Z
 *   21  RB10  OUT   DIR_Y
 *   22  RB11  OUT   STEP_Y
 *   23  RB12  OUT   DIR_X
 *   24  RB13  OUT   STEP_X
 *
 *   3   RA1   IN    DATA REQUEST
 *   6   RB2   IN    MOSI
 *   26  RB15  IN    SCLK
 *
 *   2   RA0   IN    unused
 *   12  RA4   IN    unused
 *   7   RB3   IN    unused
 *   11  RB4   IN    unused
 *   25  RB14  IN    unused
 *
 *
 */
42

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Sun Sep 15, 2013 3:01 pm

BTW, is your git repository updated?
42

Return to “Automation, sensing and robotics”