PDA

View Full Version : My project is starting



cncmachineguy
- 19th November 2010, 01:17
and I have a need for some advice/suggestions

First let me say if this should be in a different topic, PLEASE move it.

Heres the overview:
I have been working on a machine to cut foam for R/C planes. I am working on this with another guy in Ohio, so not close to me. We have our machines ready now, and of course I am behind on the electronics.

We will be using EMC2 as our machine controller. Using 2 parallel ports, we will be controlling 6 steppers, 1 spindle, and 1 hot wire. The machine also has travel limits on each end of each axis.

I have 2 interface cards based around a 16f1947, 1 for each parallel port. these are identical. each card will be responsible for passing step/dir signals through for up to 4 motors(only 3 needed in our app), enable all 4 drives independantly from a single enable output from EMC2. All the limit switches for the 4 axis will be monitored by the card. disable a drive if a limit is hit and pass the home switches back to EMC2.

Ok, enough of the basics, if anyone is intrested in more detail, just ask.

On to the problem.
Talking to a PIC from a serial port will be new to me. Bootloaders are new to me.

I can write the basic program to just do the above without any problem, but I have much more in store for this card. So I need to get the basic part done and send 2 cards to Ohio. My buddy has no need for a programmer so to get him updates I really want to send him cards pre loaded with a bootloader able to work from rs232 port.

I don't really know how to get started is my problem. Should I first play with a bootloader and get the LED blinky to work? Should I start with a serial comm program and get that to work? What bootloader should I use? If I need to change any config stuff, will I be able to do that with a bootloader?

ScaleRobotics
- 19th November 2010, 01:58
I looked to my favorite bootloader, Tiny Pic Bootloader http://www.etc.ugal.ro/cchiculita/software/picbootloader.htm, but it does not cover your chip. So I looked around, and found a Microchip Ap Note AN1302. It talks about programming multiple chips through the I2C port. I have not had a chance to read it yet, but this might be good for you. Specially since you need to program two or three chips. It has the hex files, and the PC program here: http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en546181

With the PIC18 devices you can do a run-time config http://www.picbasic.co.uk/forum/showthread.php?t=4093

But not with PIC16 devices:(. So your configs need to be right the first time. But worst case, you could fedex new programmed PICs to your friend in Ohio, if you needed to change configs. (Well at least if it's not surface mount).

Edit: By the way, sounds like a very cool project. I am going to have to read more about EMC2. I hadn't even heard about it. What is the largest span you can hot wire? Can you post any pictures?

cncmachineguy
- 19th November 2010, 02:19
Thanks Walter, I will look into the APP note. But I will only have 1 chip per card. I did put an I2C port on board :)

As for sending chips back and forth, they are TQFP's. So that option is out. Worse case is I buy a pickit2 and send him to use while I get things going as I want them. Then He can send it back and I will be part of the PK2 club. :)

But A bootloader would be too cool, just email program and presto magic.

cncmachineguy
- 19th November 2010, 02:31
Edit: By the way, sounds like a very cool project. I am going to have to read more about EMC2. I hadn't even heard about it. What is the largest span you can hot wire? Can you post any pictures?

EMC2 (http://linuxcnc.org)

We have designed it to be able to process a 24 x 48 inch piece of foam with the mill or the wire, No pics just yet, but we are about a week out with those. We jumped the gun back in july/aug with pics of our first prototype. so now he is gunshy. Also we completly redesigned it from the first one.

ScaleRobotics
- 19th November 2010, 02:31
Sorry, that won't work

"We can, however, use PC software if we use a device that will act as a master I2C device controlled by PC software. We used the PICkit™ Serial analyzer configured as an I2C master device."



Since you need a Pickit serial analyzer to make it work, it kind of defeats the purpose. Maybe this one, AN1310: http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en546974

cncmachineguy
- 19th November 2010, 02:59
Just skimed over AN1310. It sounds awesome, but of course it says it uses USART1 and of course I am setup for USART2 :(

Maybe the firmware can be modified? I will also look at the alternatives listed at the end of the note.

cncmachineguy
- 19th November 2010, 03:34
Maybe the best choice here is to skip the bootloader for now. It may be I am just a bit overwhelmed with the choices, but getting it to work is really more important then being able to upgrade the firmware in the field. Maybe on the next board rev I will look at changing the usart's but I think I wanted the pins to make something else easy. I don't remember right now.

mackrackit
- 19th November 2010, 07:16
EMC2...
Have you tried the new version using Ubunu 10 yet?

JDM
I do not normally sugest them but I have bult them into a board for cases like this. Being built in and tweaked for one chip helps their short comings.
Then use PikLab to squirt the hex.

cncmachineguy
- 19th November 2010, 09:25
Haven't tried the new version yet, but I have managed to get the live install on a USB drive and ready to install so I don't need a cd player. I imagine I will have it running over the holiday.

Jdm- I had never even heard about this programmer until I joined this forum. Building it onto the card is a cool idea, but it missed this rev. I guess I could just build one, but will it really be cost effective when a pickit2 is only $35 for just the programmer?

As an extra bonus, if I could do all this with ubuntu 10 from the machine controller, now that would be something.

Alas, I think it's prolly best to leave the field upgrade out of the equation for just now. And if I do that, I don't even need serial comm. Now I can just focus on getting the basic function done so the machines will work.

mackrackit
- 19th November 2010, 09:52
I guess I could just build one, but will it really be cost effective when a pickit2 is only $35 for just the programmer?
Is this project a one off sort of thing? If so then the PicKit2 will be cheaper in the long run.


As an extra bonus, if I could do all this with ubuntu 10 from the machine controller, now that would be something.
You can also use the PicKit2 on an Ubuntu box.

cncmachineguy
- 19th November 2010, 10:02
dave do you ever sleep? :)

About the project size, Of course we always hope somebody may want 1 besides us, at this point I am only focused on his and mine. For this I think pk2 is prolly best. I can even get him to buy his own!

I will prolly dig a little deeper into the I2C method. In the future it would be best to have a single serial connection to talk to both cards. I am sure there must be a way to not need the serial analyzer to do this. even if its a special built card that does rs232<->I2c. power levels can come from the target


yea Ubuntu!!!

mackrackit
- 19th November 2010, 13:13
dave do you ever sleep? :)

Sleep is for sissies. :D

cncmachineguy
- 20th November 2010, 00:20
I guess I must be, I seem to need at least 4-5 hours now days.

I got my cards in today :):) So I will be building my cards tomorrow morning and hopefully start programming it.

As my mind always does, I am already wondering to start thinking about an RS232 to I2c board. Anybody want in on getting something together?

mackrackit
- 20th November 2010, 03:19
As my mind always does, I am already wondering to start thinking about an RS232 to I2c board. Anybody want in on getting something together?
Might be an interesting project, but I have not used a bootloader yet of any kind.

cncmachineguy
- 20th November 2010, 03:36
Well even if it weren't a bootloader, it seems like it could have value as an interface. Yet anoyher way to talk to the animals.

mackrackit
- 20th November 2010, 04:03
Just a thought.

Have a PIC receive data from the PC serially and squirt the same data out I2C ???
That would be too easy.

cncmachineguy
- 20th November 2010, 14:58
I soldered all the smt parts on my card, uP,3311,12 volt driver, and LED's. and of course the ICSP header. Wrote a quik ASM to just turn the LED's on and off and LED's all work! This is a major milestone for me, this is my first dive into SMT.

Next up on the list, do the same thing using PBP. Of coursethis means figuring out how to pull everything together, IDE, compiling and of course setup stuff for the chip. WOW what an exciting new road I am traveling on today!!

Of course I have to post this kind of thing here, cuz you guys are the only folks I know that can appreciate these small feats.

mackrackit
- 20th November 2010, 16:25
Of course I have to post this kind of thing here, cuz you guys are the only folks I know that can appreciate these small feats.
I know what you mean.

The first time I did a blinky with a PIC it was around the holidays. I called my wife over and excitedly showed her the LED turning on and off. She looks at it for a bit, walks over to the tree, plugs it in, waits for the lights to start blinking, turns to me and says, "SO". She then leaves the room.

cncmachineguy
- 20th November 2010, 18:41
more progress, but a little confusion.

Worked through all the issues of getting everything to work together. Compiled and programmed the blink program that pops up in the MCS program. Mind you I am using MPLAB. Well heres my confusion: with the pauses left at 500, it takes about 5 sec to blink. If I change it to 50, seems about 1/2 sec as the program says it should. Now there are no config,define's, or whatnot, Any thoughts on this?

mackrackit
- 20th November 2010, 19:09
What are you using for an oscillator? Type and speed.

The default configs in the PBP directory *.inc file has the OSC set for HS.
And PBP defaults to 4MHz.

If you have an external OSC add
DEFINE OSC x
x being speed.

cncmachineguy
- 20th November 2010, 20:19
I think I just found the problem. I left too much up for granted. Being new to this chip, I never dreamed it would default to a 500K clock!

BTW, I am running intosc (apperantly at 500K, not 4M like I assumed) So I will set osccon to be 4M and see what happens :)

EDIT: How fantastic life is when you tend to the little things. now works as it should. Off to do more fun stuff :)

cncmachineguy
- 21st November 2010, 00:10
New question
Heres a snipit:


' Configure pins for digital operation (uncomment as needed).
' These settings are intended as simple examples. For more detail,
' see the appropriate device datasheet for register descriptions.
'ANSEL = %00000000 ' 16F88, 16F688, 16F690, 16F88x
'ANSELH = %00000000 ' 16F690, 16F88x
'ADCON1 = %00000111 ' 16F87x, 16F87xA, 18F452
'ADCON1 = %00001111 ' 18F4620


Why when I uncomment the ANSELH line, I get a syntax error for that line? How should I be setting it?

cncmachineguy
- 21st November 2010, 01:18
Well I don't get it, but after changing nothing, it works. go figure

mackrackit
- 21st November 2010, 10:28
Looks like, but I have not used this chip, that the ANSEL has changed some.
ANSELA
ANSELE
ANSELF
ANSELG

ANSELA = %00000000
ANSELE = %00000000
ANSELF = %00000000
ANSELG = %00000000

Maybe...

cncmachineguy
- 21st November 2010, 12:10
Well I broke my own rule of troubleshooting- NEVER change more then 1 thing at a time!! While I was trying to figure it out, I must have kept changing "define osc 4" to "define osc = 4". Playing with caps back and forth. I was relocating where I had the statement and not noticing I kept adding the = sign.

cncmachineguy
- 21st November 2010, 19:07
new question, or looking for suggestions.
I am gonna run my pic at max speed for it. thats 32 meg. The way I was going to handle my step/dir signals was to just pass them through to my drives. So my main would look something like this:


Main
portc = porta ' pass all values to C
if porte!=0 then LimitHit 'check for overtravels
goto main


Thats my whole main section. Now for my problem

If I want my interface card to look and act like a Gecko drive, their timing is this: step signal requires a min low of .5microsec and a high of 4 microsec. It occurs to me the .5uS will be 4 instructions running at 32meg so I think I could miss that pulse real easy. In fact I may miss many.

Now there are some other thing going on here, 1 I don't think EMC is updating the port that fast, and 2 I can make the pulses longer. The one thing I can't do is IOC cuz the boards made already so wrong port.

I guess I am just looking for other opinions here as to how to handle this. BTW, If i hit a limit, I don't care if I miss steps at that point.

mackrackit
- 21st November 2010, 19:45
If it is any help..
My setup has the step drive set to 5000 ns. "nano"

cncmachineguy
- 21st November 2010, 19:59
5000nS = 5uS, yes? thats 40 instructions instead of 4! so as long as I am checking within 2uS, or 20 instructions, I won't miss it. :) in fact, maybe I should just check the limits in the main, then have an interupt every 1 or 2 uS to shift the ports. then I know I won't miss any.

Thoughts?

mackrackit
- 21st November 2010, 20:20
Maybe run the latency test on EMC2 and then run the conf wizard to see what your target PC will need/do exactly.

I am only running one parallel port on a 1.3 GHz machine with 758 MB ram. Two ports may make a difference.

Those be my thoughts.

cncmachineguy
- 21st November 2010, 21:05
I am blessed with 4 8-bit timers to go with my 16 bit timer. along with some DT_INT, I should be able to make this work just wonderful!!

And that is a great idea Dave, I never really considered running 2 ports may slow things down a bit.

cncmachineguy
- 27th November 2010, 13:34
So far I have a main that just moves porta to latc on every iteration. It also checks that enable is high. If enable is low, it gosubs to disable drives, and waits there for a high again on the enable line. At which point it returns to the main to keeep passing values from porta to latc.
Also have a DT_INT every 5 mS. this does nothing but inc a counter used to flash a LED every .5 sec. That is also handled in the main. If count=100 then toggle LED

This all works :)

Now its time to step up the function here. I want to move the port passing to the int. But I am having a brain fart about the timming. The pulses last for 10uS high and 10uS low. I am thinking a 5uS interupt will ensure I NEVER miss a pulse, but my mind is cloudy on this. My int will be ASM, so no PBP context saving for entry and exit. I want to do this so I can do more stuff and never worry about missing a step.

Does this seem right?

ScaleRobotics
- 27th November 2010, 15:56
Now its time to step up the function here. I want to move the port passing to the int. But I am having a brain fart about the timming. The pulses last for 10uS high and 10uS low. I am thinking a 5uS interupt will ensure I NEVER miss a pulse, but my mind is cloudy on this. My int will be ASM, so no PBP context saving for entry and exit. I want to do this so I can do more stuff and never worry about missing a step.


You could do an interrupt on change of state for portA,

RAC_INT -- RA Port Change

Then have your interrupt routine look to see which bit has changed state.
</pre>

cncmachineguy
- 27th November 2010, 16:29
Don't I need to do that on a port with IOC? Port B seems to be my IOC port, but since B has ICSP pins, I left them dedicated to ICSP. I need all 8 pins for my control.

ScaleRobotics
- 27th November 2010, 16:36
EDIT: OOPS, you are correct, you would need IOC for portA ... Sorry...
__________________________________________________ _______________
RAC_INT is for portA.

(from http://darreltaylor.com/DT_INTS-14/intro.html )
RAC_INT -- RA Port Change (for port A)
RBC_INT -- RB Port Change Interrupt (for port B)
RABC_INT -- RAB Port Change (for port A or B)

Here is a small example for RAC_INT , but it's just for a push button.

http://www.picbasic.co.uk/forum/showthread.php?t=12447&p=82818#post82818

cncmachineguy
- 27th November 2010, 20:46
thats OK Walter, you had me thinking for the last hour or 2! :):) (Now have to reset all the smoke alarms)

But back to it, any thoughts on my timing? Anyone? My brain is still locked about this. I want to draw me some timing diagrams, but it seems I have become so dependent on puters, I don't have any suitable graph paper to do so with. I am somewhat of a stickler when it comes to these things.

mackrackit
- 28th November 2010, 00:01
Doin' what I can :D :rolleyes: :D

cncmachineguy
- 28th November 2010, 14:27
Inspired by Daves wonderful gift, I worked out some timing in my schmatic program (with snaps). It looks to me with 5uS interupts, I will not miss a single step. I will strech them sometimes and shrink them sometimes, but thats no problem. And I still have 40 instructions between interupts. Well prolly more like 30 when you account for the interupt handler itself.

So I think I am off to the races now!!

ScaleRobotics
- 28th November 2010, 14:43
So far I have a main that just moves porta to latc on every iteration.

Hey Bert,

I am trying to understand this better. Would you mind generalizing what it is your board is going to be doing? I take it that it is passing all of the data from porta to portc. But beyond that, I am in the dark. I guess your EMC2 program is sending stepper motor signals through the parallel port, to your board. Then your board is passing it to the stepper if it is enabled. Couldn't you just avoid passing it from one port to another, and act directly on the parallel port pins, or am I missing something?

cncmachineguy
- 28th November 2010, 15:26
Walter you are exactly right. I could have just passed the signals to the drives. In fact I thought about doing just that. But heres the thinking:
This will be a project to be done in several phases.
phase 1:
pass motor signals to the drives
watch limits and disable drives if hit
report to EMC a problem has occured
LED indicators for drive status (enabled or disabled)
phase 1 will give me basic functions of my machine while playing with future phases.

phase2:
add in serial comm and set some parameters such as drive current, switch offsets, and any others I can think of. My machine has mill and hotwire capabilities all built in, I am sure There will be different "Zeros" for each. I am not sure EMC can handle that. So I may have to have my board maintain an offset and get a signal from EMC to tell it which mode its in. That way The board could adjust the axis when "tool change" occurs. for this I will need to talk to the steppers.
Until Phase 2 is complete, the offset stuff will be handled in the machine program.

phase3:
Turn the card into a full controller, being able to download a G-code program to it and hit go, elimiting the need for EMC at all.
This will be a big deal and prolly take a good while.


Happy to answer any more questions, just ask.

ScaleRobotics
- 28th November 2010, 15:27
Ok, I found a scheme of the parallel port for EMC

http://gramlich.net/projects/cnc/controller/index.html

Oops, I see your answer now. Thanks Bert!

cncmachineguy
- 2nd December 2010, 03:02
I have a problem, not sure where it is. My gut feeling is its with the background things that may be happing when using DT-INT. Here is the entire program.


' Name : Interface card.pbp
' Compiler : PICBASIC PRO Compiler 2.6A
' Assembler : MPASM
' Target PIC : 16F1947
' Hardware : PIMill Interface
' Oscillator : internal
' Keywords :
' Description : PICBASIC PRO program to interface parallel port
' to 4 stepper drives and limit switches
'

'
'
'
' Configure ports
'
'
ANSELA = %00000000 'port A all digital
ANSELE = %00000000 'port E all digital
ANSELF = %00000000 'port F all digital
ANSELG = %00000000 'port G all digital

CM1CON0 = %00000000 'No comparaters
CM1CON1 = %00000000
CM2CON0 = %00000000
CM2CON1 = %00000000

' preload latches before setting direction
LATB = %00000000
LATC = %00000000
LATD = %00010000 'LED's 0 for red, 1 FOR GREEN should start red
LATF = %00001111 ' low nibble is drive enable. 1 disables
LATG = %00000000

' I/O direction

TRISA = %11111111'step and dir inputs
TRISB = %11000001'7-0 icsp,icsp,h4o,h3o,h2o,h1o,estopO,enable In
TRISC = %00000000'step and dir outputs
TRISD = %00000000'led6,i2c,i2c,led5,led4,led3,led2,led1
TRISE = %11111111'ls4,lsh4.ls3,lsh3,ls2,lsh2,ls1,lsh1
TRISF = %00010000'spindle dir,servo out,dac out,flood input,4en,3en,2en,1en
TRISG = %11100111'x,x,icsp/mclr,rly2,rly1,Rx2,Tx2,DI




'REMOVE THIS LINE IF NOT SETTING THE CONFIGS IN CODE SPACE
@ __config _CONFIG1,_FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
@ __config _CONFIG2,_WRT_OFF & _VCAPEN_OFF & _PLLEN_ON & _STVREN_OFF & _BORV_25 & _LVP_OFF

'Internal osc setup
OSCCON = %01110000 'clock is 8 meg. turn on PLL for 32 meg clock
DEFINE OSC 16 ' 32 meg not allowed according to book. be sure to double things that need this

'Variables
LED0 VAR LATD.0 ' Assign name "LED" to PORTD
LED1 VAR LATD.1
LED2 VAR LATD.2
LED3 VAR LATD.3
LED4 VAR LATD.4
LED5 VAR LATD.7
CNT VAR BYTE

ENALL VAR PORTB.0
BSRSTORE VAR BYTE

EN1 VAR LATF.0
EN2 VAR LATF.1
EN3 VAR LATF.2
EN4 VAR LATF.3
ASM
#DEFINE EN1A LATF,0 'stuff for testing

ENDASM
wsave VAR BYTE $70 SYSTEM
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
'INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR2_INT, _FiveMicroSec, ASM, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

'5.0 uSec OR 200,000 Hz INTERRUPTS

T2CON = %00000100 'Prescaler = 1:1, TMR2ON

'PRELOAD 223 "FROM MULTI-CALC"
PRELOAD VAR byte
PRELOAD = 239 ' FROM TESTING TO FIND THE RIGHT NUMBER
TMR2 = PRELOAD

@ INT_ENABLE TMR2_INT ; enable Timer 2 interrupts

Main: 'DO WHATEVER YOU WANT HERE


IF CNT=200 THEN
TOGGLE EN2
TOGGLE LED1
CNT=0
ENDIF
TOGGLE LED2
GOTO Main



'---[TMR2 - interrupt handler]--------------------------------------------------
FiveMicroSec:
TMR2 = PRELOAD 'THIS LINE
TOGGLE EN1 'AND THIS LINE
CNT =CNT+1 'WITH THIS CREATE A INT ROUTINE EVERY 4.99uS
' LATC = PORTA 'ADDING THIS LINE CHANGES THE TIME TO 5.245uS!!
' SO WHY DOES THIS CHANGE THE TIMING?@ INT_RETURN



Now It doesn't make sense to me. I am running a 32mHz clock. 5 uS interupt should takes 160 clock cycles, or 40 asm instructions. my interupt routine has 3 PBP instructions when working and 4 when I add the LATC=PORTA line. I can't imagine that would be 40 lines of ASM. I have tried to do this with a pure ASM handler, but I can only get it to work if I toggle LATA instead of LATF. I am sure this is a bank select issue. I can work through that if I must, but I would really like to use PBP instead.

Maybe all the time is taken up with the entry and return? Also note the large disparity between what I thought the preload should be and what it is.

mackrackit
- 2nd December 2010, 03:36
Not much help but

OSCCON = %01110000 'clock is 8 meg. turn on PLL for 32 meg clock
DEFINE OSC 16 ' 32 meg not allowed according to book. be sure to double things that need this
I think should be

OSCCON = %11110000 'clock is 8 meg. turn on PLL for 32 meg clock
DEFINE OSC 32 ' 32 meg is allowed according to book. be sure to double things that need this

??
But I could be wrong

rmteo
- 2nd December 2010, 04:29
A timer preload of 239 indicates you have only 16 CPU (or ASM) cycles available - looks like 24 cycles are consumed by overhead.

cncmachineguy
- 2nd December 2010, 04:48
And I guess it makes sense that the overhead is in entering the interupt. Otherwise those cycles would be part of the "timer cycle" and not have to be adjusted for in the preload. I think at this point I have 2 options, either use pure ASM interupts and/or increase my timing to 8uS. Maybe I will look at how many instructions it takes to enter the interupt if using pure ASM. This will be the deciding factor I guess. Clearly there is some lag needed to enter the handler, but is it 24 cycles?

cncmachineguy
- 2nd December 2010, 05:16
@Dave, You know I would have bet my left pinky 32 was NOT in the list when I looked up DEFINE OSC, but low and behold it sure is. Thanks for making me look again. As for the bit 7 of OSCON, the way I read it is it is ignored if PLL is enabled in my config-which I think I did. Won't hurt to set it though.

mackrackit
- 2nd December 2010, 10:33
the way I read it is it is ignored if PLL is enabled in my config-which I think I did. Won't hurt to set it though.
Yup, my mistake.

cncmachineguy
- 2nd December 2010, 14:02
Thanks Dave, Never hurts to have a second set of eyes on. specialy since I always forget my safty glasses.

Maybe I should bring this interupt question up in its own thread? I would sure like some input to see if there is something I should be doing different or if I have found the "limit" for DT_INT speed?

ScaleRobotics
- 2nd December 2010, 15:06
Darrel has a post in here somewhere that says how many instruction cycles an ASM type interrupt has, but I am having a heck of a time trying to find it. I remember it being substantially fewer than PBP type, but can't remember the number. I will try looking some more.

mackrackit
- 2nd December 2010, 21:51
http://www.picbasic.co.uk/forum/showthread.php?t=3251&p=17587#post17587

70 cycles are mentioned.

ScaleRobotics
- 2nd December 2010, 22:21
70 cycles are mentioned.

Yes, 70 instructions cycles to save the registers, and 70 instruction cycles to restore them, but that is for PBP type interrupts. But for ASM type interrupts it is much shorter. I think it is something like 12 or 22 instruction cycles. But then, I can't find it in here or my brain.

mackrackit
- 2nd December 2010, 22:37
http://darreltaylor.com/DT_INTS-14/SPWM.html

???

ScaleRobotics
- 4th December 2010, 17:58
For those following this thread, see thread split here for more information about assembly DT_INTS interrupts : http://www.picbasic.co.uk/forum/showthread.php?t=14063

cncmachineguy
- 4th December 2010, 18:07
Thanks Walter, I was wanting to figure out how to include the other thread so to speak. There is heaps of good stuff in it, so I am glad its not buried in this one.

cncmachineguy
- 5th December 2010, 20:00
Well, not that I need to be thinking about this yet, but in anticpation of "phase III" Anybody have any ideas for ram? I think I will be looking for at least 2-4K. The more the merrier. I do have scads of DDR sticks, that would be cool. Or I was thinking about SD cards, they would be way convinent. But at this point I am still just thinking.

mackrackit
- 5th December 2010, 20:26
SD is kind of slow, I here FRAM is fast.

cncmachineguy
- 5th December 2010, 21:04
Pretty cool looking stuff that F-RAM. I ordered some samples of the 5V I2C 512Kb guys. From Mouser I can buy them (Ok, $11 each for these big guys) but free samples is free! I really doubt i need this big. The 64Kb (yes boys and girls - thats kilo-bit) are only $3.xx each in small numbers.

Thanks Dave, now I can go back to finishing phase I :)

Ioannis
- 5th December 2010, 22:25
...FRAM is fast.

And they never wear...

Ioannis

cncmachineguy
- 12th December 2010, 20:04
Here is my latest code. All this really does is check for switches and disable drives, and shift PORTa to PORTc every 5 uS. It also sends a servo pulse out every 20mS with a pulse time sweeping from 1-2 ms just for testing purposes.

Right now, everything seems to work, but I need to remove the RED line from the interupt. When I comment it out, it seems to hang in the interupt and never leave. Uncomment and it works again. I have been struggling with this for a week, so I figured I would just ask and get the answer.


' Name : Interface card.pbp
' Compiler : PICBASIC PRO Compiler 2.6A
' Assembler : MPASM
' Target PIC : 16F1947
' Hardware : PIMill Interface
' Oscillator : internal
' Keywords :
' Description : PICBASIC PRO program to interface parallel port
' to 4 stepper drives and limit switches
'

'
'
'
' Configure ports
'
'
ANSELA = %00000000 'port A all digital
ANSELE = %00000000 'port E all digital
ANSELF = %00000000 'port F all digital
ANSELG = %00000000 'port G all digital

CM1CON0 = %00000000 'No comparaters
CM1CON1 = %00000000
CM2CON0 = %00000000
CM2CON1 = %00000000

' preload latches before setting direction
LATB = %00000000
LATC = %00000000
LATD = %00010000 'LED's 0 for red, 1 FOR GREEN should start red
LATF = %00001111 ' low nibble is drive enable. 1 disables
LATG = %00000000

' I/O direction

TRISA = %11111111'step and dir inputs
TRISB = %11000001'7-0 icsp,icsp,h4o,h3o,h2o,h1o,estopO,enable In
TRISC = %00000000'step and dir outputs
TRISD = %00000000'led6,i2c,i2c,led5,led4,led3,led2,led1
TRISE = %11111111'ls4,lsh4.ls3,lsh3,ls2,lsh2,ls1,lsh1
TRISF = %00010000'spindle dir,servo out,dac out,flood input,4en,3en,2en,1en
TRISG = %11100111'x,x,icsp/mclr,rly2,rly1,Rx2,Tx2,DI




'REMOVE THIS LINE IF NOT SETTING THE CONFIGS IN CODE SPACE
@ __config _CONFIG1,_FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
@ __config _CONFIG2,_WRT_OFF & _VCAPEN_OFF & _PLLEN_ON & _STVREN_OFF & _BORV_25 & _LVP_OFF

'Internal osc setup
OSCCON = %11110000 'clock is 8 meg. turn on PLL for 32 meg clock
DEFINE OSC 32

'Variables
LED0 VAR PORTD.0 ' Assign name "LED" to PORTD
LED1 VAR PORTD.1
LED2 VAR PORTD.2
LED3 VAR PORTD.3
LED4 VAR PORTD.4
LED5 VAR PORTD.7

SERVO VAR PORTF.6
CNT VAR BYTE

MYFLAGS VAR BYTE
COUNTUP VAR MYFLAGS.0
COUNTDN VAR MYFLAGS.1
MS VAR MYFLAGS.2

ENALL VAR PORTB.0
TEMPF VAR BYTE
FRAMECOUNT VAR BYTE
POS VAR BYTE
EN1 VAR PORTF.0
EN2 VAR PORTF.1
EN3 VAR PORTF.2
EN4 VAR PORTF.3

COUNTUP = 1
COUNTDN = 0
POS = 1
FRAMECOUNT = 0
MS = 0
CNT = 0

'5.0 uSec OR 200,000 Hz INTERRUPTS
'PRELOAD 39 PR = NUMBER OF CYCLES-1
'INT HANDLER COMPLIMENTS OF DARREL TAYLOR
PRELOAD VAR byte
PRELOAD = 39 ' FROM TESTING TO FIND THE RIGHT NUMBER
PR2 = PRELOAD
PIE1.1 = 1 ; Enable Timer2 interrupts
INTCON.6 = 1 ; enable PEIE
INTCON.7 = 1 ; enable GIE
T2CON = %00000100 ; Start Timer2

DEFINE INTHAND _FiveMicroSec

'---[TMR2 - interrupt handler]--------------------------------------------------
FiveMicroSec:
LATF = LATF ^ 1 ; TOGGLE EN1
CNT =CNT+1

PORTC = PORTA
PIR1.1 = 0 ; clear the interrupt flag
@ NOP
@ RETFIE


Main: 'DO WHATEVER YOU WANT HERE

IF ENALL = 0 THEN
GOTO NOTREADY
ELSE
GOTO READY
ENDIF
READYRETURN:
IF CNT >= 200 THEN
' TOGGLE EN2
TOGGLE LED5
CNT=0
FRAMECOUNT = FRAMECOUNT + 1
MS = 1
ENDIF
IF FRAMECOUNT >=20 THEN
FRAMECOUNT = 0
MS=0
HIGH SERVO
IF COUNTUP THEN POS = POS + 1
IF COUNTDN THEN POS = POS - 1
ENDIF

' TOGGLE LED2
IF PORTE != $FF THEN SWITCHHIT

GOTO SERVOCHECK
GOTO Main

SERVOCHECK:
IF MS =1 THEN
IF CNT >= POS THEN
LOW SERVO
MS =0

IF (COUNTUP = 1) AND (POS=199) THEN
COUNTUP = 0
COUNTDN = 1
ELSE
IF POS = 1 THEN
COUNTUP = 1
COUNTDN = 0
ENDIF
ENDIF
ENDIF
ENDIF
GOTO MAIN
SWITCHHIT:
PORTF = PORTF | $0F
IF (PORTE = 253) OR (PORTE = 254) THEN LED0 = 0
IF (PORTE = 247) OR (PORTE = 251) THEN LED1 = 0
IF (PORTE = 223) OR (PORTE = 239) THEN LED2 = 0
IF (PORTE = 127) OR (PORTE = 191) THEN LED3 = 0
' ELSE PORTE = PORTE |$0F
GOTO MAIN

NOTREADY:
PORTD = PORTD & $F0
PORTF = PORTF | $0F
IF ENALL = 0 THEN NOTREADY
PORTD = PORTD | $0F
PORTF = PORTF & $F0
GOTO MAIN
READY:
PORTF = PORTF & $F0
PORTD = PORTD | $0F
GOTO READYRETURN

cncmachineguy
- 13th December 2010, 01:48
I am used to using the "watch" part of MPLAB to step through a program and look at SFR's and variables. But with PBP program, I see 1 step seems to go several (I assume because of the number of instructions required for a line of code). So as I step through my program, PIE1.1 doesn't change when it clearly should.

I just don't know HOW to debug using PBP. In this aspect, right now ASM seems easier. Someone PLEASE keep me from going back to the darkside!!

Darrel Taylor
- 13th December 2010, 16:08
With Timer2 firing off every 5uS, you're not going to be able to do any meaningful single stepping.

The interrupt flag will be set again while you are looking at the last "step".

cncmachineguy
- 13th December 2010, 19:09
well if Debug with ICD3 does not hold the timer to inc only on an instruction cycle, then that makes sense. Now to the real problem, any idea why I can't rem out the
LATF = LATF ^ 1 line? With it in the int routine, all seems to work. but if I rem it, it doesn't work. I am checking with a scope and not by single stepping. Also led5 doesn't blink. So I am assuming CNT is not being incremented, which to me says it is not getting out of the int.

Darrel Taylor
- 13th December 2010, 19:37
In your code from post #58, execution will "Fall into" the ISR, never making it to the Main loop.

Either put the handler after the main loop, or add a GOTO that jumps over the ISR.

cncmachineguy
- 13th December 2010, 20:29
Well color me silly!! Ok, I will try that tonight when I get home, Thanks Darrel. I will post my success or failure, what ever the case may be.

cncmachineguy
- 14th December 2010, 02:06
Well here is the modification:


DEFINE INTHAND _FiveMicroSec

GOTO MAIN

'---[TMR2 - interrupt handler]--------------------------------------------------
FiveMicroSec:
LATG = LATG ^ 4 ; TOGGLE EN1
CNT =CNT+1

PORTC = PORTA
PIR1.1 = 0 ; clear the interrupt flag
@ RETFIE


Main: 'DO WHATEVER YOU WANT HERE
As you can see. the only change between last post and this is
addition of goto main and changed LATF to LATG. The goto main does seem to make it start better, but still can't rem the LATG - LATG ^4.

Darrel Taylor
- 14th December 2010, 17:05
I do not see that problem here.
It doesn't make any difference when the LAT line is commented.

Please tell me that this 5uS doohicky is not running a hobby servo????

cncmachineguy
- 14th December 2010, 18:12
I do not see that problem here.
It doesn't make any difference when the LAT line is commented.

Thats too bad. OK, I will keep struggling with it. The way I am deciding it doesn't work is like this. A) LED5 does not flash anymore, and B)even though you have pointed out I can't single step with TMR2, It does seem to when LAT is not remed. When it is remed, single step makes it appear to stay in the handler. But I have a few more ideas to try. Thanks for looking at it.

Maybe I am not reming correct. I am putting a ' in the beginning of the line. such as this


' LATG = LATG ^4




Please tell me that this 5uS doohicky is not running a hobby servo????

Would it be TOO much overkill?? No, The servo is just to check 1 output. The entire card is a 4 axis controller with a control for a brushless spindle motor driven from a hobby ESC. The 5uS int is to make sure no steps are missed from the controlling computer. When all is done, the machine is really a 6 axis machine with 2 of these cards running 3 axis each. All this just to cut foam airplanes!!

cncmachineguy
- 15th December 2010, 13:26
Well I have no idea whats wrong, and seemingly no way to figrue it out, so for now I will just leave the LAT in. I have re-defined what output it flips so as not to be in the way of my actual use. So far I have tried rem ('), and erasing the whole line. on both tests I just compile and program, board stays in interupt. (Or just sits somewhere). un rem or put the line back in and volia it runs again. I did this about 20 times just to be sure it wasn't something I was doing. I even replaced it with a @NOP just to see if it was some kind of memory placement hic-cup.

One thing I didn't think to try was changing it to toggle a variable instead of an output. I will try that tonight.

On the good news side of things, The board and program work as desired (as long as LAT line is there). Now for some cleanup things and add in the serial com to change things like spindle speed. I am sure there will be more issues when this is attempted, but hey, thats all the fun :)

Phase 1 almost complete!

Darrel Taylor
- 15th December 2010, 16:14
On the good news side of things, The board and program work as desired (as long as LAT line is there).
That's too bad.
I was going to suggest doing it a different way.

If the inputs on PORTA were moved to PORTB, you could use the IOC interrupts to transfer everthing to PORTC.
Then it only interrupts when the pins change, leaving much more time for the main program.

Oh well, too late.

cncmachineguy
- 15th December 2010, 18:06
There was some reason I didn't want to use PORTB. Maybe cuz I like to leave the ICSP pins for just only that. In hindsight, and maybe moving forward, I may change it. For now it's just fine. In the current configuration there really is not much for the MAIN to do, and its not time critical. This phase is really just a stepping stone to the planned use for this. somewhere back in this thread, Walter had asked why move the step/dir through the chip at all. Short answer was as a stepping stone.

When I get to phase 3 of this project, the 5uS interupt won't be needed at all. :) (post 39 shows my plans)

Thank you for your help Darrel.

cncmachineguy
- 19th December 2010, 21:29
I think I have found the problem with interupt. When the interupt hangs and won't leave, it seems BSR=5, when this happens PIR1.1 doesn't get cleared so it just re-enters the int. So the question is, why doesn't PBP make sure the BSR=0 before it tries to PIR1.1=0?

Or the bigger question is why does it work for Darrel???

I am posting the program as it is right now, I am using MPLAB, chooseing MPLAB SIM from the debugger menu. then choose the >> not > to animate the program. With this you can see it enter the interupt and leave. I left it running for about 30 min without issue. rem the LAT line and instant hang. sometimes it takes a few times through to get stuck.

PLEASE, can I get a few people to try this so at least I will know I am not going crazy!!



' Name : Interface card.pbp
' Compiler : PICBASIC PRO Compiler 2.6A
' Assembler : MPASM
' Target PIC : 16F1947
' Hardware : PIMill Interface
' Oscillator : internal
' Keywords :
' Description : PICBASIC PRO program to interface parallel port
' to 4 stepper drives and limit switches
'

'
'
'
' Configure ports
'
'
ANSELA = %00000000 'port A all digital
ANSELE = %00000000 'port E all digital
ANSELF = %00000000 'port F all digital
ANSELG = %00000000 'port G all digital

CM1CON0 = %00000000 'No comparaters
CM1CON1 = %00000000
CM2CON0 = %00000000
CM2CON1 = %00000000

' preload latches before setting direction
LATB = %00000000
LATC = %00000000
LATD = %00010000 'LED's 0 for red, 1 FOR GREEN should start red
LATF = %00001111 ' low nibble is drive enable. 1 disables
LATG = %00000000

' I/O direction

TRISA = %11111111'step and dir inputs
TRISB = %11000001'7-0 icsp,icsp,h4o,h3o,h2o,h1o,estopO,enable In
TRISC = %00000000'step and dir outputs
TRISD = %00000000'led6,i2c,i2c,led5,led4,led3,led2,led1
TRISE = %11111111'ls4,lsh4.ls3,lsh3,ls2,lsh2,ls1,lsh1
TRISF = %10010000'manual ready,servo out,dac out,flood input,4en,3en,2en,1en
TRISG = %11100111'x,x,icsp/mclr,rly2,rly1,Rx2,Tx2,SPINDLE ON




'REMOVE THIS LINE IF NOT SETTING THE CONFIGS IN CODE SPACE
@ __config _CONFIG1,_FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
@ __config _CONFIG2,_WRT_OFF & _VCAPEN_OFF & _PLLEN_ON & _STVREN_OFF & _BORV_25 & _LVP_OFF

'Internal osc setup
OSCCON = %11110000 'clock is 8 meg. turn on PLL for 32 meg clock
DEFINE OSC 32
DEFINE NO_CLRWDT 1

'Variables
'Port assignments
'------------------port B
ENALL VAR PORTB.0
ESTOPO VAR PORTB.1
HO1 VAR PORTB.2
HO2 VAR PORTB.3
HO3 VAR PORTB.4
HO4 VAR PORTB.5
'------------------port D
LED0 VAR PORTD.0
LED1 VAR PORTD.1
LED2 VAR PORTD.2
LED3 VAR PORTD.3
LED4 VAR PORTD.4
LED5 VAR PORTD.7
'------------------port F
EN1 VAR PORTF.0
EN2 VAR PORTF.1
EN3 VAR PORTF.2
EN4 VAR PORTF.3
DIGIN VAR PORTF.5
SERVO VAR PORTF.6
MANREADY VAR PORTF.7
'------------------port G
SPINON VAR PORTG.0
RLY1 VAR PORTG.3
RLY2 VAR PORTG.4
'---------------------Bytes
CNT VAR BYTE
FRAMECT VAR BYTE
POS VAR BYTE
MYFLAGS VAR BYTE
PRELOAD VAR BYTE
SPEED VAR BYTE
DUMRUN VAR BYTE
'---------------------Bits
COUNTUP VAR MYFLAGS.0
COUNTDN VAR MYFLAGS.1
MS VAR MYFLAGS.2
LIMIT VAR MYFLAGS.3
DRIVEON VAR MYFLAGS.4
HOMED VAR MYFLAGS.5
'---------------------INIT VARIABLE VALUE
COUNTUP = 1
COUNTDN = 0
POS = 127
FRAMECT = 0
MS = 0
HOMED = 0
CNT = 0
SPEED = 0
PRELOAD = 39 'PRELOAD 39 PR = NUMBER OF CYCLES-1

'5.0 uSec OR 200,000 Hz INTERRUPTS
'INT HANDLER COMPLIMENTS OF DARREL TAYLOR
PR2 = PRELOAD
PIE1.1 = 1 ; Enable Timer2 interrupts
INTCON.6 = 1 ; enable PEIE
INTCON.7 = 1 ; enable GIE
T2CON = %00000100 ; Start Timer2

DEFINE INTHAND _FiveMicroSec

GOTO START

START:
GOSUB NOTREADY


Main: 'DO WHATEVER YOU WANT HERE
IF DRIVEON = 0 THEN
GOSUB CHECKREADY
ENDIF
IF (ENALL = 0) AND (DRIVEON = 1) THEN
GOSUB NOTREADY
ENDIF
IF (MANREADY = 0) AND (DRIVEON = 1) THEN
GOSUB NOTREADY
ENDIF
IF (LIMIT = 1) AND (PORTE = $FF) THEN
GOSUB READY
ENDIF
IF SPINON THEN
SPEED=POS
RLY1 = 1
ELSE
SPEED = 0
RLY1 = 0
ENDIF
IF DIGIN THEN
RLY2 = 1
ELSE
RLY2 = 0
ENDIF

READYRETURN:
IF CNT >= 200 THEN
TOGGLE LED5
CNT=0
FRAMECT = FRAMECT + 1
MS = 1
ENDIF
IF FRAMECT >=20 THEN
FRAMECT = 0
MS=0
HIGH SERVO
ENDIF

IF PORTE != $FF THEN
GOSUB SWITCHHIT
ENDIF
GOSUB SERVOCHECK
GOTO Main

SERVOCHECK:
IF MS =1 THEN
IF CNT >= SPEED THEN
LOW SERVO
MS =0
ENDIF
ENDIF
RETURN

SWITCHHIT:
IF HOMED=0 THEN
GOTO HOMESWITCH
ENDIF
ESTOPO = 1
PORTF = PORTF | $0F
IF (PORTE = 253) OR (PORTE = 254) THEN LED0 = 0
IF (PORTE = 247) OR (PORTE = 251) THEN LED1 = 0
IF (PORTE = 223) OR (PORTE = 239) THEN LED2 = 0
IF (PORTE = 127) OR (PORTE = 191) THEN LED3 = 0
LIMIT = 1
DRIVEON = 0
RETURN

HOMESWITCH:
IF PORTE = 253 THEN HO1=1
IF PORTE = 247 THEN HO2=1
IF PORTE = 223 THEN HO3=1
IF PORTE = 127 THEN HO4=1
IF PORTE = 85 THEN HOMED = 1
RETURN
NOTREADY:
PORTD = PORTD & $F0
PORTF = PORTF | $0F
DRIVEON = 0
HOMED = 0
RETURN

CHECKREADY:
IF ENALL = 0 THEN RETURN
IF MANREADY = 0 THEN RETURN
IF LIMIT = 1 THEN RETURN

READY:
PORTD = PORTD | $0F
PORTF = PORTF & $F0
DRIVEON = 1
LIMIT = 0
RETURN

'---[TMR2 - interrupt handler]--------------------------------------------------
FiveMicroSec:
LATF = LATF ^ 32 ; TOGGLE DAC
CNT =CNT+1

PORTC = PORTA
PIR1.1 = 0 ; clear the interrupt flag
@ RETFIE

cncmachineguy
- 19th December 2010, 21:45
Don't know why I need it, but this works:



FiveMicroSec:
' LATF = LATF ^ 32 ; TOGGLE DAC
CNT =CNT+1
BSR = 0
PORTC = PORTA
PIR1.1 = 0 ; clear the interrupt flag
@ RETFIE


I mean, I get why setting BSR=0 fixes it, just don't know why I need to.

mackrackit
- 20th December 2010, 23:34
Just a shot in the dark....


CNT VAR BYTE BANK 0

cncmachineguy
- 21st December 2010, 00:49
OHH, great idea!! Thanks Dave, I will try this now.

So sad, got an error : Bad BANK number

mackrackit
- 21st December 2010, 02:35
Have you tried any of this in real life? Or just SIM?

cncmachineguy
- 21st December 2010, 03:15
its all in real life. I only use the MPLAB SIM when I have a problem I can't reason out, like why does the int hang. for that i need to see registers. But it showed up in real life first by my LED not flashing.

Darrel Taylor
- 21st December 2010, 03:16
Further explanation after my reply (http://www.picbasic.co.uk/forum/showthread.php?t=14145&p=97478#post97478)in the "Bug" thread.

When there was ...

LATF = LATF ^ 1

LATF is is BANK7, and since PBP thought it was in BANK0, it would have changed to BANK7 to access LATF, and at that point it knew it was in BANK7.
So then it changed back to BANK0 to access CNT, PORTA, PORTC etc.

When the LATF statement was commented, it thought it was still in BANK0, and didn't try to change the bank, not knowing what bank it was really in at the start of the interrupt.

Remember that this type of ASM interrupt using PBP statements, goes against the standard rules of interrupts.

I'm still embarrassed though. :o

mackrackit
- 21st December 2010, 03:27
I'm still embarrassed though. :o
Why???

So
BSR = 0
at the beginning of the ISR will do what with LATF?

I thought it had something to do with being in the wrong bank, but like you said CNT was already in BANK 0.


Remember that this type of ASM interrupt using PBP statements, goes against the standard rules of interrupts.

How should this be done? I am getting more confused than normal.

cncmachineguy
- 21st December 2010, 03:55
I think PBP assumes its in BANK0 unless it does something in a different bank. Since LATF is not in BANK0, PBP will clear the BSR after executing LATF line. When I comment LATF line, sometimes the Interupt occurs during an instruction where BSR !=0, so in the interupt PBP assumes BANK0 for the BANK0 stuff.

Does this make sense? Setting BSR=0 upon entering the ISR will make sure PBP is not confused :)

Thank you Darrel for letting me keep some of my hair so I can pull it out on the next problem.

cncmachineguy
- 21st December 2010, 04:01
Remember that this type of ASM interrupt using PBP statements, goes against the standard rules of interrupts.


Well I am not too sure where the standard rules for interupts can be found, but in this instance, I am using PBP statements but ignoring all PBP context when entering and exiting the ISR. If I had actually written this in ASM, I MAY not have had this problem because I MIGHT have remembered to set BSR to what I needed. But at least I would NOT have thought it was a PBP issue.

At the end of the day, it is really my lack of understanding how PBP thinks. Now that I realize PBP assumes BANK0 all the time (maybe I even read that in the manual), I see why this is broke and why it is my fault as the programmer.

cncmachineguy
- 21st December 2010, 04:04
When the LATF statement was commented, it thought it was still in BANK0, and didn't try to change the bank, not knowing what bank it was really in at the start of the interrupt.


How did Protus make this work???

mackrackit
- 21st December 2010, 04:25
BSR = 0 'IN BANK 0
LATF = LATF ^ 32 'NOW IN BANK 7
CNT =CNT+1 'NOW WHAT???

If I am just being thick headed let me know...

cncmachineguy
- 21st December 2010, 04:44
when PBP sees the LATF line, it switches to bank 7. when its done it automaticlly switches back to BANK 0. This way PBP can know it is always in BANK 0. So when it sees PIR1.1=0, this is a BANK 0 thing, it assumes it is in BANK 0 so it doesn't reset BSR. Now sometimes when my ISR is called, I was already in BANK 5. If the LATF line is in, PBP switches to 7, then back to 0 when done with LATF. When I rem LATF and enter the ISR in BANK 5, PBP doesn't know. So then everything that is supposed to happen in BANK 0 can't.

Adding BSR=0 as the first line in my ISR will ensure PBP won't be confused. Because the chip I am using does auto context save and restore, I don't need to worry about destroying the BSR in my ISR.

mackrackit
- 21st December 2010, 05:01
I get it now..
LAT was/is doing the same thing as BSR , as far as the BANKs are concerned.
Thanks!!!!
now it is time for a nap..

cncmachineguy
- 21st December 2010, 05:13
now it is time for a nap..

I thought sleep was for sissies?

mackrackit
- 21st December 2010, 05:18
I thought sleep was for sissies?
Did I say that? :p

but it will be a short nap ;)

Darrel Taylor
- 21st December 2010, 05:23
How did Protus make this work???

Because I was concentrating on the interrupts, and not simulating your entire program.
So it never ended up in other banks like your program.

Oh well.
Sorry for the confusion.

cncmachineguy
- 21st December 2010, 05:31
Whew, thanks again Darrel. I was really having second thoughts for a min. Now my brain is all re-aligned for whatever tomorrow brings :)

cncmachineguy
- 21st December 2010, 15:47
I get it now..
LAT was/is doing the same thing as BSR , as far as the BANKs are concerned.


For the sake of clarity, LAT was not really doing the same thing as BSR. What it was doing was causing PBP to change banks to BANK7, therefore PBP also changed banks back to BANK0 when the LAT was done. With it remed, PBP assumed it was still in BANK0. SO when I entered the ISR with a different bank set, PBP didn't know. I gather from Darrels help in my "bug" thread, He tends to the BSR=0 in his DT_INT routine to avoid just such issues.

BTW, the only reason I can change BSR inside my ISR is because 16F1xxx automatically saves BSR upon entering an interupt. So BSR will change back when I return. Otherwise I would have needed to save the BSR to a temp, then restore it before leaving ISR.

Next up on the list of games is multiple interupts and checking who fired. :)
This is great fun!!!

cncmachineguy
- 1st February 2011, 01:11
Been a while since I posted anything here. I am still working on this but things slowed through the holidays then I had some mechanical issues to resolve with the machine. But I am back on this now. Anyhow, here is my problem:

I have limit switches on each axis of travel. 1 switch also doubles as a home switch for each axis. Because I have too much I/O to report everything to EMC, I am using my card to watch the switches. This way I can report the "home" switches and throw an E-stop if any other limits are hit.

Now for the question: when the machine homes, it is set up to do 1 axis at a time, leaving the axis on the home switch. I need to be able to ignore the switch until homing is complete (i have that working) but also need to ignore them until the first time the axis moves off the switch. Does this make sense? I am sure this will need some flags, but I am at a loss as to how to do the checking without having a zillion IF's and so forth.

Any suggestions/questions?

cncmachineguy
- 14th February 2011, 15:14
Finally got past my logic issues, Just thought I would post a pic of the card with stepper drives attached.
5167

Thanks to all who have helped me get this far. This is a fully functional "phase 1" card. Now the fun really begins :)

BTW, for any who are intrested, pics of the machine will be up soon over at Foam Casualty

mackrackit
- 15th February 2011, 00:45
Nice!!!
Looking forward to seeing vids of it running.

cncmachineguy
- 15th February 2011, 01:56
Thank you,
They are coming Dave :)