Lets go back a little
http://www.picbasic.co.uk/forum/show...4621#post94621
Lets go back a little
http://www.picbasic.co.uk/forum/show...4621#post94621
Dave
Always wear safety glasses while programming.
I have not learned to SEARCH the forum.
How about I return to basics. How about I make my controls interrupt driven. If had an interrupt routine that ran every 20msec, I could create a true-so-spec PWM signal and I could measure rate of closing speed for each SONAR. I think the 16F887 can get all my work done in 20msec. If not I can up the PIC power.
Way back someone told me how to set up such an interrupt system. Where is that? It's Monday morning. Time to get moving.
Ken
Yes, I looked at Olsson's routines. I got distracted by the thought that my 16F887 is just not up to the task at hand.
I glanced through the MicroChip 18F PICs. My eye fell on the PIC18F46K20.
It comes in 40 pin PDIP format. That is good. It has lots more code memory space. It is on the list of devices that can be programmed by my PICKIT 2 and my Microcode Studio PICBASIC PRO combination. It must be bigger, faster, more capable than my 16F887. True? Which 18F should I choose. I have little to no sense of the differences.
Ken
Ken, What makes you think your current device is not up to the task? R/C systems are very slow IMHO relative to processors. Think on this, pulses for the car happen for 1-2msec each every 20 msec. so 2 pulses (drive & steering) will be max 4 msec. That leaves 16 msec for the uP to do whatever like measure distance and decide what to output next. At 4Mhz clock, thats 16000 ASM instructions! Not PBP instructions but still a whole lot!
So heres a couple of thoughts: Use pulseout for the signals to the car. No need for int or PWM. How about connecting 1 of the car signals from the receiver to your pic. Then just check to see if the pin went high, if so its time to send out commands. This way you can use the car receiver as a 20mSec clock.
-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 also think the PIC16 or 18 is plenty fast for the application. But the servo's and speed controllers are pretty picky about their signals. They need to be at regular intervals in order for the servo's and speed controllers to work smoothly. Otherwise their operation can be erratic. While you could measure the receiver with pulsin, I would stick to interrupts for the servo and speed controller. The PIC18F4431 has hardware that allows for R/C pwm frequencies. But it could be done with pretty much any PIC using spwm. I would probably use a PIC18 rather than a PIC16 because it opens up a couple of possibilities, but both are powerful enough.
http://www.scalerobotics.com
Hi Walter, quick question. I am under the impression most Rx send their pulses sequencially, so when channel 1 is done, 2 starts, 2 done 3 starts... I know they are not always in numeric order, but none the less they wait until the last is don befor sending the next. At least with a little older equipment.
If my assumption is correct, in a 4 channel Rx, channel 4 could start anywhere between 4mSec to 8mSec after the start of the 20mSec frame. (channel 1,2 and 3 could be all min or all max). If this is true, They can't be too picky cuz 4 mSec is pretty darn big!. I would think it would take little effort to hit the 20mSec loop within .1msec.
so I was thinking in the main loop, don't measure the pulse from the Rx, just see if it went high. Then within a couple of instructions the "send pulses" routine would start. When thats done, acquire the next distance reading (10 mSec) then back to the old main loop waiting for the next trigger from the Rx.
Of course if my assumption is not correct, this was a nice typing excerise for me![]()
-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 do not have any experience with the 18F46K20 but two things that I think would make it a good one for this project are:
AndInternal Oscillator Block:
- 8 user selectable frequencies, from 31 kHz to
16 MHz
- Provides a complete range of clock speeds
from 31 kHz to 64 MHz when used with PLL
Enhanced CCP module: In PWM mode, this
module provides 1, 2 or 4 modulated outputs for
controlling half-bridge and full-bridge drivers.
Dave
Always wear safety glasses while programming.
Hey Ken,
I know a lot of people prefer on interrupt type. But my vote for easy interrupt is to use Darrels instant interrupts (and I think an equally large number of people like them as well). Here is a simple example of a blinky interrupt using his include files. The pages on this site have a lot of information about the different kinds of interrupts you can do. Your chip needs to use DT_INTS-14. And of course DT_INTS-18 is for PIC18 devices.
http://darreltaylor.com/DT_INTS-14/blinky.html
Last edited by ScaleRobotics; - 19th November 2010 at 16:20.
http://www.scalerobotics.com
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!
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