Hello Don Luis,
IMHO you need assy interrupts, and I recommend you use Darrel's Instant Interrupts. On Interrupt services the interrupt when it gets around to it, given all the things you have going on, you need interrupts that actually interrupt.
Hello Don Luis,
IMHO you need assy interrupts, and I recommend you use Darrel's Instant Interrupts. On Interrupt services the interrupt when it gets around to it, given all the things you have going on, you need interrupts that actually interrupt.
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Thanks for answering Archangel.
I don’t know the meaning of IMHO, but I appreciate your comment, now I am terrified to ask, do I have to do the hole code in assy?, I mean I been working on this project for over a year, you know, bumping my head around to get the hang of pbp, even blowing a couple pics and a few other components, I don’t main, there is no rush, just want to see it completed an working as I want to, I do not know anything about assembler, but yet I willing to learn if that is what it takes, on the meaning time I’ll take a look at Darrel’s interrupts.![]()
IMHO = In My Humble Opinion, good luck. Funny I don't even use cell phone . . .
No ooooooodo I have to do the hole code in assy?
Here is a timer1 demo I made tonight for 16F690
All this does is overflow the timer and display the results in PICKit2 USART display. It has Darrel's Instant Interrupts installed so you can pretty much copy paste, then use your registers as requiredCode:@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BOR_OFF & _FCMEN_OFF & _IESO_OFF INCLUDE "DT_INTS-14.bas" ; Darrel Taylors instant interrupts DEFINE OSC 4 ; * * * * * * * * * * * * * Setup Darrel's Instant Interrupts * * * * * * * * ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR1_INT, _Flash, ASM, no endm INT_CREATE ; Creates the interrupt processor ENDASM @ INT_ENABLE TMR1_INT ; enable external (INT) interrupts ; * * * * * * * * * * * * * Provide system variables to save return address' * * * * ;wsave VAR BYTE $20 SYSTEM ; location for W if in bank0 wsave VAR BYTE $70 SYSTEM ; alternate save location for W ; * * * * * * * * * * * * SETUP DEBUG Parameters * * * * * * * * * * * * * DEFINE DEBUG_MODE 0 ' Debug sending True serial data DEFINE DEBUG_REG_PORTA ' Debug Port = PortA as required by PICKIT2 serial Monitor DEFINE DEBUG_BIT 0 ' Debug.bit = PortA.0 DEFINE DEBUG_BAUD 19200 ' Default baud rate = 9600 DEFINE DEBUGIN_REG PORTA' Debug Port = PortA as required by PICKIT2 serial Monitor DEFINE DEBUGIN_BIT 1 ' Debugin bit PortA.1 DEFINE DEBUGIN_BAUD 19200' Default baud rate = 9600 DEFINE DEBUGIN_MODE 0 ' Debugin receiving data true = 0 inverted = 1 ; * * * * * * * * * * * * Setup Timer 1 registers * * * * * * * * * * * TMR1IF var PIR1.0 ' Explain to PBP which bit is the T1IF bit INTCON = %11010000 ; GIE,PEIE,T0IE,INTE set RABIE,T0IF,INTF,RABIF cleared PIR1 = %00000000 PIE1 = %00000001 ; -,ADIE ,RCIE ,TXIE ,SSPIE ,CCP1IE,TMR2IE,TMR1IE T1CON = %01000101 ; T1GINV,TMR1GE,T1CKP,T1CKP,T1OSCEN,T1SYNC,TMR1CS,TMR1ON CM2CON1 = %00000000 temp var word overFlow var word overFlow = 0 temp.highbyte = 0 temp.lowbyte = 0 main: if temp.lowbyte >= 255 then temp.highbyte = temp.highbyte +1 endif if temp >= 65535 then overFlow = overFlow + 1 ;track number of temp roll overs endif debug " Temp Var High = ",#temp.highbyte," Temp Var Low = ",#Temp.Lowbyte," ",10 debug "OverFlow = ",#overFlow," temp var ",#temp,10 goto main ; * * * * * * * * * * * * * End of Main Function * * * * * * * * * * * * * @ INT_DISABLE TMR1_INT Flash: if TMR1IF then ; Flash is the ISR temp = temp + 1 ; add 1 to timer roll over count endif TMR1L = 0 ; preload timer 0 with ? of 255 allows you to set counts until reset TMR1H = 0 TMR1IF = 0 ; Clear T1 Interrupt flag bit @ INT_ENABLE TMR1_INT @ INT_RETURN
Last edited by Archangel; - 23rd July 2013 at 11:00.
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Hi Don, here my suggestion. If your max encoder count is not bigger of 65535 then you can feed your encoder pulses directly to timer1 input (pin 15 of you 16f877). Timer1 has to be set as a counter using "T1CON = %00000111" and then you have two ways to control your motor.
1) You poll the timer1 register TMR1H and TMR1L to see when the count reaches the desired value to stop the motor.
Or
2) you use DT interrupt (as already suggested) and you just load the count in Timer1 register (you have to load the complement : 65535-desired count) and wait for the overflow. In other words when the count is reached the value of the timer1 counter will be 65535 and adding one pulses it will overflow invocking the interrupt. In this routine (called ISR) you will stop your motor.
If your needed count is greater then 2^16 it it still possibile to use timer1 as a counter but in this case interrupt is mandatory.
Cheers
Al.
Last edited by aratti; - 23rd July 2013 at 11:38.
All progress began with an idea
Hi guys:
Aratti; I already tried tmr1 interrupt on overflow, as you are suggesting, I explained that, on my post on July 21st, it’s just that seem to take too long to stop the motor and I get much more than I am barging for, sort of speech, also tried external interrupts on RB.0, and lastly polling from what I got much better results if you like to take a look to that post, I even included the code I used for each attempt.
Archangel; thank you for that, I already took a look to Darrel’s page and downloaded his .bas files and included, them on the PBP folder, (I feel relief now), but I’ll to try this first, since I got everything setup, and due to that I have fairly good results on polling, using the same encoder disc it measures twice de input because it is counting up on every negative and positive pulse, so just finished while ago a disc with 75 slot’s about half the other one, if still no good output then I try Darrel’s code, I’ll let you all know as soon as I get around it.
I suggested timer1 overflow with a true interrupt (Darrel Taylor interrupt) your code didn't use any interrupt.I already tried tmr1 interrupt on overflow, as you are suggesting,
You can try to use this simple snippet which uses the timer1 as a counter, without interrupt and works pretty well.
Naturally you need to complete the code replacing the parts with ?????? and Xx with reference to your hardware setup.Code:False con 0 True con 1 Z0 Var Byte Cnts var word Tape_Len Var Word Logic_1 var portXx ' any available free input Motor = False Brake = False TMR1H = 0 TMR1L = 0 Main_Loop: If ????? goto Load_Tape If ????? goto Set_Tape_L goto Main_loop Set_tape_L: Tape_Len = XXXXX ' encoder pulses derived from the tape lenght desired return Start_Motor: Brake = False Motor = True Return Stop_Motor: Motor = false Brake = True Pause 200 Brake = False T1CON.0 = False Return Load_Tape: Cnts = 0 TMR1H = 0 TMR1L = 0 T1CON.0 = true Resume_Halt: Lcdout $FE, 1, " Press Yy to stop " Lcdout $FE, $C0, "--------------------" Lcdout $FE, $94, "Now Loading Tape ..." Lcdout $FE, $D4, "Loaded: ",dec Cnts Gosub Start_Motor For Z0 = 0 To 100 ' 100 millisecs delay pause 1 if Logic_1 = True then Hw_Halt ' check if emergency stop is activated Next Z0 Winding: ' loading start here Cnts.highbyte = TMR1H Cnts.lowbyte = TMR1L If Cnts => Tape_Len then gosub Stop_Motor ' if count = lenght desired stop motor goto Main_Loop End If if Logic_1 = True then Hw_Halt ' If emergency stop key pressed stop motor Lcdout $FE, $D4, "Loaded: ",dec Cnts ' display updated count goto Winding Hw_Halt: gosub Stop_Motor Emergency_menu: 1) if ????? then goto Resume_Halt 2) if ????? then goto Main_Loop goto Hw_Halt End
Cheers
Al.
Last edited by aratti; - 25th July 2013 at 16:48.
All progress began with an idea
Bookmarks