I don't think you want on interupt, just my opinion from reading the manual. I think you want to figure out DT int. Seems to be true int without Dealing with ASM.
I don't think you want on interupt, just my opinion from reading the manual. I think you want to figure out DT int. Seems to be true int without Dealing with ASM.
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
I agree that DT's interrupts or ASM's are the way to go. I gave the ON INTERRUPT code above as an example to get started. Ken will still need to know how pre-scalers and such work no matter what.
Ken seems to want to know the nuts and bolts of things. In my opinion getting a simple code to work with ON INTERRUPTS is a crawl/walk thingy.
I am not real clear on how the motor driver works. I understand it as PWM greater than 127 turns one way and less than 127 turns the other way??
I just drove home trying to simulate Ken's car. Pulsed the same degrees left or right, more pulses left or right for turns but always the same, say 5 degrees off center, and after each pulse returned to center.
What about a two chip solution. The main chip will do nothing more than
center, pulse left, center, pulse right, center...
Second chip deals with the sonar. If a correction needs made a given pin is toggled.
The main chip is using an interrupt on change and completely interrupt driven. The main chip can deal with the pulse left, center, pulse right while the other chip is busy with the next calculation.
Just a half baked thought.
Dave
Always wear safety glasses while programming.
How'd that work out for you?
@Ken, Clearly there is some learning/teaching to be done here. What would you like to start with? DT_INTS or pre scaling and such?
For DT_INTS, I am gonna grab a copy and look/learn it myself. I will prolly jump on the learning side with you when you are ready to go through it. There are plenty here that will be able to answer any/all of our specific questions.
As for the pre scaler, I will go grab a copy of your datasheet. I agree with Dave, this is something you should understand even if you don't need it just yet.
BTW, PIE1 is Peripheral Interupt Enable 1. Without looking (yet) at the datasheet, I am guessing that is the enable for timer 1. In ASM, to use interupts, you must do 2 things. GIE must be set (Global Interupt Enable) this allows any interupt to do its thing. then you must set each interupt enable you want to use such as PIE1. Now with DT_INTS, I think that may be taken care of as part of the include, but I am not sure just yet.
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
Worked well until I pulled up to the checkpoint doing it. Thought they were going to take me to secondary...How'd that work out for you?
Ken,
Here is code using DT's INTs giving an interrupt at 200 Hz.
All I did was tweak Darrel's blinky example.
Code:<font color="#008000"><b><i>'FL PIC16F887 '16F887 DT INT RUPT '44 PIN DEMO BOARD 'REMOVE THIS LINE IF NOT SETTING THE CONFIGS IN CODE SPACE </i></b>@ __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF </font><font color="#0000FF"><b>OSCCON </b></font>= <font color="#800000"><b>%01100000 </b></font><font color="#008000"><b><i>'4 Mhz </i></b></font><font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>OSC </b></font><font color="#800000"><b>4 </b></font><font color="#0000FF"><b>LED1 </b></font><font color="#FF0000"><b>VAR </b></font><font color="#0000FF"><b>PORTD</b></font>.<font color="#800000"><b>4 </b></font><font color="#0000FF"><b>wsave </b></font><font color="#FF0000"><b>VAR BYTE </b></font><font color="#800000"><b>$70 </b></font><font color="#0000FF"><b>SYSTEM </b></font><font color="#FF0000"><b>INCLUDE </b></font><b><i>"DT_INTS-14.bas" </i></b><font color="#008000"><b><i>' Base Interrupt System </i></b></font><font color="#FF0000"><b>INCLUDE </b></font><b><i>"ReEnterPBP.bas" </i></b><font color="#008000"><b><i>' Include if using PBP interrupts </i></b></font><font color="#FF0000"><b>ASM </b></font><font color="#008000">INT_LIST macro <b><i>; IntSource, Label, Type, ResetFlag? </i></b>INT_Handler TMR1_INT, _ToggleLED1, PBP, yes endm INT_CREATE <b><i>; Creates the interrupt processor </i></b></font><font color="#FF0000"><b>ENDASM </b></font><font color="#008000"><b><i>'5.0 mSec OR 200 Hz INTERRUPTS </i></b></font><font color="#0000FF"><b>T1CON </b></font>= <font color="#800000"><b>%00000001 </b></font><font color="#008000"><b><i>'Prescaler = 1:1, TMR1ON 'PRELOAD 60543 </i></b></font><font color="#0000FF"><b>PreLoad </b></font><font color="#FF0000"><b>VAR WORD </b></font><font color="#0000FF"><b>PreLoad </b></font>= <font color="#800000"><b>60543 </b></font><font color="#0000FF"><b>TMR1L </b></font>= <font color="#0000FF"><b>PreLoad</b></font>.<font color="#0000FF"><b>LowByte TMR1H </b></font>= <font color="#0000FF"><b>PreLoad</b></font>.<font color="#0000FF"><b>HighByte </b></font><font color="#008000">@ INT_ENABLE TMR1_INT <b><i>; enable Timer 1 interrupts </i></b></font><font color="#0000FF"><b>Main</b></font>: <font color="#008000"><b><i>'DO WHATEVER YOU WANT HERE </i></b></font><font color="#FF0000"><b>PAUSE </b></font><font color="#800000"><b>1000 </b></font><font color="#FF0000"><b>HIGH </b></font><font color="#0000FF"><b>PORTD</b></font>.<font color="#800000"><b>7 </b></font><font color="#FF0000"><b>PAUSE </b></font><font color="#800000"><b>1000 </b></font><font color="#FF0000"><b>LOW </b></font><font color="#0000FF"><b>PORTD</b></font>.<font color="#800000"><b>7 </b></font><font color="#FF0000"><b>GOTO </b></font><font color="#0000FF"><b>Main </b></font><font color="#008000"><b><i>'---[TMR1 - interrupt handler]-------------------------------------------------- </i></b></font><font color="#0000FF"><b>ToggleLED1</b></font>: <font color="#FF0000"><b>TOGGLE </b></font><font color="#0000FF"><b>LED1 </b></font><font color="#FF0000"><b>TOGGLE </b></font><font color="#0000FF"><b>PORTC</b></font>.<font color="#800000"><b>6 </b></font><font color="#008000"><b><i>'CONNECTED TO METER </i></b></font><font color="#0000FF"><b>TMR1L </b></font>= <font color="#0000FF"><b>PreLoad</b></font>.<font color="#0000FF"><b>LowByte </b></font><font color="#008000"><b><i>' Load the timer with preload value. </i></b></font><font color="#0000FF"><b>TMR1H </b></font>= <font color="#0000FF"><b>PreLoad</b></font>.<font color="#0000FF"><b>HighByte </b></font><font color="#008000">@ INT_RETURN </font>
Dave
Always wear safety glasses while programming.
Hi Ken, Just looked over section 6. I always think about the prescaler like this:
With no prescaler, timer increments as I posted earlier, Every 4 counts of the ocs will inc the timer by 1. If you have prescale set to 2, timer will inc every 8 counts, or half as fast. set to 4 it will inc every 16 counts or 1/4 speed, and set to 8, timer will inc every 32 counts or 1/8 speed. does this make sense?
So in summary, the prescaler is really a clock divider for the timer.
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
Quick question, how did you determine the preload value? I mean to say, I understand what it represents, just how did you determine the offset?
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
Dave
Always wear safety glasses while programming.
Not much luck reading DT_INTS-14. I do not understand ASM and all the macros that have been written.
Soooo I installed the two blinky programs and they both looked correct. I activated the LOGIC TOOL from PICKIT2 and looked carefully at the 20millisec square wave. Close enough for government work. Next I changed the
command toTOGGLE PORTC.6 'CONNECTED TO METER
and hooked up Channel 2 of the LOGIC TOOL to PORTD.7.PWM PORTD.7, 127, 1
I expected to see a single pulse every 20millisec. I even hoped that the pulse would be 1.5millisec long.
I see many pulses seemingly not related to the edges of the interrupt driven 50Hz square wave. I would show you all a picture, but my FastStone Capture is screwed up.
Is there any PWM-like command that makes one pulse ranging from 1millisec to 2millisec in 256 gradations?
Ken
Right now I want an interrupt every 5 millisec. With a 1megahz clock and a 65356 counter, every 5 millisec is every 5000 ticks of that clock. cncmachineguy suggests that I generate an interrupt each time the clock gets down to 60356 by pre-setting the TIMER1 counter.
I understand that, but have not the faintest notion how to accomplish it. I have gone to Darrel Taylor's site. It is well written, but I do not see how it helps me.
Please help me get an interrupt every 5 millisec. Then I can try to figure out what code is needed to control the little car.
Ken
Bookmarks