Log in

View Full Version : A few 12F683 questions



dhouston
- 22nd May 2008, 18:15
I recently lost a HDD and with it my notes on a project. So, I have a few questions for which I hope to find answers, saving a bit of research effort.

I will be using a 12F683 (8MHz internal oscillator) and an ASK RF receiver module with +/-10kHz bandwidth to capture several RF codes from various sources. The codes vary in frequency (310-320MHz), start sequence (initial pulses vary from ~2mS to 9mS), length (i.e.number of bits), and protocols. Some have constant length pulses with the following spaces varying for 1 vs. 0 (e.g. NEC) while others are just the opposite with constant length spaces preceded by pulses that vary in length (e.g. Sony). In each case, it's the time between rising edges that determine 1 or 0. The long bit-times are 2.0-2.4mS and the short ones half of that. All but one of the codes terminate with a lengthy silence. The longest code has 44 bits. The one code that does not have a terminating silence has a 2mS start pulse while the only code with 44 bits has a 9mS start pulse so I can determine which is which based on their start pulses. I also wish to measure the amplitude of the RF receiver's analog output. I've found that measuring the modulation depth (pulse amplitude - space amplitude) is an excellent proxy for RSSI (Received Signal Strength Indicator). I do not plan to use interrupts.

My algorithm...

1. Wait for rising edge
2. Measure amplitude of start pulse
3. Wait for falling edge
4. Calculate duration of pulse - if out of limits reset and wait for next pulse
5. Measure amplitude of space (pulse-space=RSSI)
6. Capture up to 44 bits - using CCP1 set for rising edges - reset TMR0 to overflow at ~2.6mS
7. Output results via RS232 (and store for response to RS485 query).

The algorithm itself works fine using another processor (ZX-40a from ZBasic) although the timeout function is slightly different. It uses an overall timeout value rather than the 2.6mS value I plan to use on a per bit basis.

My questions:

1. How do I set the TMR1 prescale value to 2?
T1CON=%00010000?
2. What values (preset, prescale) do I need for TMR0 for a 2.6mS overflow?
TMR0=93?, OPTION_REG=%10000011?
3. With interrupts disabled, can I monitor the IOC flag (INTCON.0) to detect when there's an input on one of the two serial inputs (RS232 & RS485)? They will send $FF one or more times to get the receiver's attention.

skimask
- 22nd May 2008, 21:45
1. Yes...
2. Sounds about right to me...
3. Datasheet says you've gotta have INTs enabled...but the way it reads, it almost sounds like you don't NEED to have them enabled, in which case, you'd have to read the individual bits themselves.

dhouston
- 23rd May 2008, 17:04
Thanks for confirming my timer configurations.

On #3, I think we read the datasheet the same way. I believe most, if not all, interrupt flag bits get set whether or not interrupts are enabled. For example, the CCP1 Capture flag (PIR1.2) gets set even though interrupts are disabled. For most, this is usually stated explicitly in the datasheet but, in this case, the datasheet is a bit murky. Since I'll be using While !Capture:Wend loops to wait for rising/falling edges, I'll also monitor the IOC flag (INTCON.0) within the loops and then check the individual pins to determine whether it was set by an RS232 input or RS485 input. Otherwise, I'll just monitor both input pins within the loops.

Bruce
- 23rd May 2008, 19:37
#2. With a Timer0 reload value of 93, OPTION_REG = %10000100 would give you ~2.6mS
overflow rate @8MHz.

Note there's a 2-cycle inhibit period when writing to Timer0.

#3. Yes. I do this all the time. You can enable individual interrupts and just monitor/reset
each flag bit without global interrupts enabled.

dhouston
- 23rd May 2008, 20:33
Thanks, Bruce.

#2 That's what I get for doing the math in my head.

#3 Actually, I'm adapting (i.e. stealing) one of your examples for the capture module.

mister_e
- 24th May 2008, 01:19
No need for math... PICMultiCalc is all you need :D

http://www.mister-e.org/pages/utilitiespag.html

dhouston
- 24th May 2008, 03:54
No need for math... PICMultiCalc is all you need :D
My copy was on the dead HDD and I couldn't recall the name.