Nav-Lights Variation Project Help
#1
Posted 13 November 2003 - 10:12 AM
The chip I want to use is the PIC12F675, which has both timer 0 and 1. I'm trying to come up with a way to measure the pulse width of the output of the Rx channel (servo output), however, using the internal 4MHz oscillator (which I have to do, do to pin limitations), the count on the timer is 10, if set up for a 10us timer. The problem with this is that I will be doing some other code, and may miss the timer timing out.
The 10us would be a nice resolution for the timer, however, I guess I could make it longer. I wouldn't want it to be any greater than about 50us though.
Any ideas? Should I use interrupts or just stick with using the interrupt flag? I really don't want to do the timing in software, unless necessary.
Any help is appreciated.
Jason.
#2
Posted 13 November 2003 - 10:53 AM
My usual technique {when using the internal oscillator} involves state table driven code that is synced to the R/C pulse. With the PIC12C50X series PICs, I just monitor the T0 count for overflow, as well as employ loop driven machine cycle counters. The code is efficient, minimizes measurement jitter, and offers reasonable servo pulse resolution. However, it is bothersome when I port it to my other designs since the state counts need to be recalculated.
There are so many different ways to skin this cat -- just do what you feel the most comfortable with.
#3
Posted 14 November 2003 - 07:29 AM
So, by "synced to the R/C pulse," I assume that you start your code looking for the edge of the servo pulse, then wait in a software loop for the for the other edge of the pulse, afterward, you take care of all the other tasks that you have to do, because at this point, you have some 18ms before you expect the next pulse? Is this why you say that it minimizes measurement jitter, because you don't do anything else while waiting to measure the entire pulse, and end up overshooting the actual pulse?
Would another method of doing this be to use the interrupt on pin change to catch the pulse, and have the measurement as part of the interrupt service routine?
I have a couple other questions.
1. What is considered a “glitch?” Is this just a pulse that is less than ~1ms and greater than ~2ms?
2. What does an Rx channel (servo output) put out when the Tx is turned off?
Thanks again for the help!
#4
Posted 14 November 2003 - 07:49 AM
That about sums it up....Is this why you say that it minimizes measurement jitter...?
Yes, you can use that method.Would another method of doing this be to use the interrupt on pin change to catch the pulse, and have the measurement as part of the interrupt service routine?
You will need to open up that spec a bit. Some Tx's can easily go beyond the 1mS spread, perhaps by at least +/-20%.What is considered a “glitch?” Is this just a pulse that is less than ~1ms and greater than ~2ms?
Generally, anything from a steady logic state to wild random twitches. The Rx's front end is running open ended, so the poor thing will do what it can to decode noise.2. What does an Rx channel (servo output) put out when the Tx is turned off?
#5
Posted 14 November 2003 - 08:56 AM
The data sheet says that a global /GPPU must be enabled for individual pull-ups to be enabled. Does that mean that bit should be cleared to enable pull-ups?
Jason.
#6
Posted 14 November 2003 - 09:07 AM
#7
Posted 21 November 2003 - 03:46 PM
I'm using a 2N2222A made by Motorola, and I'm not getting the brightness that I expect from the LEDs (when I run them off of the power supply with the same resistor, I get a lot more brightness). I measured the Vce across the transistor, and when it's turned on, it has a Vce drop of 2.18V. Is this normal? Is this transistor not the same as the PN2222A that is used in the Nav-Lights project? What Vce are you expecting with the PN2222A part? I assume not much, since you are using resistor values that don't figure in Vce, right?
Thanks for the help.
#8
Posted 21 November 2003 - 03:53 PM
#9
Posted 21 November 2003 - 03:58 PM
Thanks.
Edited by geogecko, 21 November 2003 - 03:59 PM.
#10
Posted 21 November 2003 - 04:10 PM
Now that I have the strobe working, I need to mess with the timing of the servo signal...
Thanks.
#11
Posted 25 November 2003 - 07:09 AM
;***
INIT_TMR1
;*** Initialize Timer 1 to give 20ms delay
CLRF T1CON ;Stop Timer 1, Internal Clock Source,
;T1 Oscillator Disabled, Prescaler = 1:1
CLRF TMR1H ;Clear Timer 1 High Byte Register
CLRF TMR1L ;Clear Timer 1 Low Byte Register
CLRF INTCON ;Disable Interrupts
BSF BANK_SW ;Switch to BANK 1
CLRF PIE1 ;Disable Peripheral Interrupts
BCF BANK_SW ;Switch to BANK 0
CLRF PIR1 ;Clear Peripheral Interrupts Flags
MOVLW 0x00 ;Internal Clock Source with 1:1 Prescaler
MOVWF T1CON ;Timer 1 is Stopped and T1 Oscillator
;is Disabled
;Set Up Timer 1 for 20ms Overflow
MOVLW 0xB1 ;Timer 1 High Byte Register
MOVWF TMR1H
MOVLW 0xE0 ;Timer 1 Low Byte Register
MOVWF TMR1L
BSF T1CON,TMR1ON ;Timer 1 Starts to Increment
RETURN
;***
Does this seem correct if running off the internal 4MHz oscillator?
The only thing I'm doing in the main routine if the interrupt flag has not been set, is a call to a routine, a bit test which does not branch, a goto, and a return, and that's it. When there is an interrupt flag set, I have way less than 20ms worth of code to run, because that would be something like 20,000 instruction cycles.
Thank you!
Edited by geogecko, 25 November 2003 - 07:11 AM.
#12
Posted 25 November 2003 - 08:08 AM
#13
Posted 25 November 2003 - 08:29 AM
You must reload the timer at each overflow/interrupt. Otherwise, your new timer value will default to 0xffff (approx 65mS).I don't have to reset TMR1H and TMR1L to the 0xB1 and 0xE0 respectively, after I get an interrupt flag, right? Maybe that is my problem?
Also, your interrupt routines must take the time to save all the common registers. Otherwise the registers can be corrupted by the branch to the interrupt calls. These sort of details are handled by higher level languages like PBasic or C; PIC assembly coders have to roll up their sleeves and ensure that all the little details are covered.
#14
Posted 25 November 2003 - 10:30 AM
Is PicBasic a free tool? I'm just used to the assembly, because that's what we used in school, however, it would probably be a lot easier to use the basic compiler.
#15
Posted 25 November 2003 - 11:01 AM
I think there are a couple of related links at the Links and Web Resource Sites forum.
#16
Posted 02 December 2003 - 07:34 PM
When you give an instruction such as "BCF TRISB ^ 0x80,1" or "MOVWF OPTION_REG ^ 0x80" is this for every register that is above address location 0x80? I see that the OPTION_REG for the 12F675 is at address 0x81, so wouldn't XORing an 0x80 with the OPTION_REG change the value of what was in data bit 7? Why would you want this? I guess I'm not following why this is used. It seems to me that you would want to make sure that bit 7 of the ADDRESS is a 1 when in Bank 1, but not the data bit 7. Am I understanding this wrong?
Thanks again for all your help.
Jason.
Edited by geogecko, 02 December 2003 - 07:35 PM.
#17
Posted 02 December 2003 - 10:02 PM
#18
Posted 03 December 2003 - 08:41 AM
As for the next step in my project, I was going to use 0.8ms and 2.2ms as my limits for a valid pulse coming from the receiver for a servo. Does this sound about right? I will have a resolution down to 1us, so I can pretty much set up any limits I like. I'm going to assume that anything below the 0.8ms is a glitch, however, I'm not sure what to consider anything above 2.2ms as? Should this also be considered a glitch, or sould I just throw out the measurement, and try again?
#19
Posted 03 December 2003 - 11:27 AM
Your R/C signal limits sound fine. There are situations on some Tx's where their ATV/EPA's, when applied against worse case mixes, will go beyond your chosen values. There isn't a formally agreed upon standard out there, so what you choose is personal preference.
#20
Posted 03 December 2003 - 12:41 PM
It's strange that a standard isn't out there. I guess that servo manufactures may have different standards as well, or maybe they only go by the strict 1ms to 2ms, and not worry about the rest... I'm going to give it a try, and see what happens. I'll be more than happy to provide my code once it is finished.
Thanks. Jason.



