Up to page 19 in DS33014K
At last I am getting the correct reference materials.
DS33014K is telling me about MPASM Assembler, Library and Linker.
I have ordered from Belgrade "PIC Microcontrollers". It is being shipped by air. That alone is pretty amazing. Just a little paperback book.
I have also found an online book at:
http://www.mikroe.com/en/books/picmcubook/ch0/
It may be the same book only on line. I am old fashioned. I like to read from paper.
I have plenty of studying to do. Thank you again and again.
Ken
mackrackit: where do I get your .INC
I copied your code snip from POST #73 at 3:02 on the 28th of January.
I noticed in the .asm code that it wanted to:
INCLUDE "MACKRA~1.MAC"
There is no such file in my computer. Do I need a copy? May I have one?
Also the compiler complained that:
Error 118: "Overwriting previous address contents (2007)
Page 157 of DS33014K says that Error 118 occurred because "Code was previously generated for this address" I assume it is talking about address (2007). I do not see where in the .asm code this is happening. I do not even know what to look for.
Ken
I need to send one pulse every 20ms
Mackrackit,
From what I understand your code will do a PWM every time TMR0 overflows.
What I need to do is make this overflow happen every 20ms. That is 50 pulses per second. We have a 4 meg oscillator. If I were designing this counter I think I would have it set to 20,000 each time it overflows. I gather from page 74 of the Data Sheet that this is not possible. The biggest prescaler is 256.
How about a routine that counts these interrupts until 1/50 of a second has elapsed then calls PWM? I would have it send one pulse out pin 1 with the duty as defined by "duty". It would look like
PWM 1,duty,1
I have found a section on Timers in a book called Running Small Motors with PIC Microcontrollers that has an example of MicroEngineering Labs code that makes an eight digit LCD display the time in hours, minutes and seconds. I think this code must do something like I need.
Ken
My book fell open to the correct page.
"Running Small Motors with PIC Microcontrollers" says, on page108
"A pre-scaler is applied to the system clock and affects the timer by slowing down the system clock as it applies to the timer. Normally the timer is fed by a fourth of the basic clock frequency, which is called Fosc/4. In a system running a 4 MHz the timer sees a clock running at 1 MHz. If the pre-scaler is set for 1:8, the clock will be slowed down by another eight times, and the timer will see a clock at 125kHz."
"The post-scaler setting determines how may overflows will go by before an interrupt is triggered."
If I pre-scale TMRO 1:256 I will get overflows at about 4K per second. If I add a post-scaler of 1:64 I will end up with about 62 interrupts per second.
Close enough for government work?
Ken
OOPs. There is only one scaler.
I just found in DS33023 section 11.6.
"There is only one pre-scaler available which is mutually exclusively shared between Timer 0 and Watchdog Timer."
So I have to count the 4000 Interrupts per second using a
FOR CNT To 80
NEXT
loop. That will give me much closer to 50 pulses per second.
Correct?
I think I am beginning to understand.
It seems to me that the most important feature that must be continuously timed in my RC car in autonomous control is the 50 pulses per second Pulse Width Modulated simulation of the RC Receiver to Electronic Speed Control signal. Doing this job in background with one Interrupt sounds correct.
The oscillator seen by TMR0 with pre-scaler runs at 1000000Hz
The pre-scaler 1:256 cuts that down to 3906.25. ie 4kHz.
A post-scaler of 1:64 cuts this down to 61.035Hz. Close enough is my guess. I don't have a grip on how to code this yet. Do I at least understand the concept?
-----------------------another way---------------
Bruce suggests counting up to 20,000 in bits of 1 microsecond. That should be easy enough with a 16 bit register built from TMR1H and TMR1L.
------------now how do I get only one PWM pulse?----------------
Page 135 of the PBP manual seems to indicate that the command:
PWM Pin,Duty,Cycle
will produce "Cycle" number of pulses. It says, "This PWM cycle is repeated "Cycle" times." It also says that, "If a 4mHz oscillator is used, each "Cycle" is about 5ms long."
This seems to mean that the following command:
PWM 1, 75, 1
would produce one pulse about 1.5msec long. This is the neutral pulse for a ESC.
If this is true then writing a routines to control the drive wheels and the steering servo will not be difficult at all.
What do you think?
Ken
Feeling a bit overwhelmed
Guys and Gals,
I might take a side trip to a scenic view along this road.
Here is a pointer to a BASIC (which BASIC I do not know) program that controls a toy level RC car. Toy levels have no Electronic Speed Control. The DC motor and servo are driven by direct current controlled by four DPDT switches. (Bang-Bang: full speed forward, full stop, full speed back.) This project has only autonomous control. The radio receiver has been eliminated. These simplifications plus the fact that the details are on the WEB make this diversion very tempting.
http://letsmakerobots.com/files/wall_racers.bas
and
http://letsmakerobots.com/node/928
I have an appropriate RC car.
I have a spare PICkit2.
I need to translate wall_racers.bas into PBP.
I need to adapt the resulting ASM to my 16F887.
I think I have enough proto. parts for both projects.
My ego needs a boost.
Ken:
1 Attachment(s)
Lookit this great picture
On the other hand==>
Look at this great oscilloscope-like picture of the PWM pulses (fifty per second) very close to 1.75ms long created by Bruce's PAUSEUS technique. I finally figured out the Analyzer part of the PICkit 2 Logic Tool.
Ken
It compiles and measures!!
Fritsl's code compiles and runs on my PICkit2.
The proximity detector (Devantech SRF05) responds with different size pulses (depending on the distance from it to an echoing object) when queried by this code.
Next to prove out control of the four DPDT switches which steer DC to the motor and to the servo, destroy the toy car by ripping out its radio receiver. and figure out how to mount the PICkit, the switches board and the two SRF05's.
Question. Is there any way that I can read through the PICkit programmer what is happening in real time to some of the variables. How do I think about adding debugging code?
Ken
I've got the proto car together.
Individually the parts of the system seems to pass their tests.
The DPDT switches worked according to their truth tables.
The proximity switches echoed what looked like sensible responses.
The wheels turned and the steering responded as the DPDT switches asked of them.
However, the car does not work as a system. The PIC is running. The proximity sensors have LED's that blink when pulsed. These work. After a while the proximity detectors stop. All this is in the code, but the steering does not move at all. The wheels do not reverse when something is seen to be right in front of the car.
Question is: What kinds of debugging power do I have once the code is in the PIC besides the Logic Tool Analyze mode?
Ken
5 ch RC PWM measurement with pass through
I made some progress with 5 channel PWM measurement using a single pin. Curently 5 RC channels are being measured using capture on a PIC12f683. Right now, only one channel is being passed through, but it is possible to get a max of 4 channel pass through on this chip. Bruce gave me the idea of measuring all 5 channels on one pin with his remote code learning thread: http://picbasic.co.uk/forum/showthread.php?t=12555
I need to work on getting channel 1 to be recognized as channel 1. Somehow, I need to check for a low on CCP1 for 3ms or so (between channel 5 and channel1). Anyone got a suggestion on how to do this?
Right now, you have to restart the circuit a few times to get channel 1 output to be channel 1 input. It sometimes selects channel2,3,4 or 5 (depends when you turn the chip on, and which rise it sees first). But the output now is pretty rock solid, no jitters.
I tried to label my ASM pretty well, but I need to work on this overall, especially the variables.
total words used = 275
http://scalerobotics.com/PWMpassthrough.html
They talk about using MPLAB IDE
I see in the PICkit 2 Programmer HELP menu discussion of the Debugger tool. Part of MPLAB IDE.
Trouble is, the programmer in MPLAB seems to not get along with the programmer in PICkit 2. I have not been able to make hide nor hair of MPLAB IDE. I have been using Microcode Studio PBP and PICkit 2 programmer.
What am I missing?
KEn