Why 6KHz? Not sure if the PIC may run as this slow... Internal is free, and gives 1-2 more i/o.
i need another cofee...
Why 6KHz? Not sure if the PIC may run as this slow... Internal is free, and gives 1-2 more i/o.
i need another cofee...
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
The 6KHz oscillator is to get under the 10KHz limit to avoid FCC testing of our product. I do not need a fast clock to handle the inputs involved and clock accuracy is not critical. I have the PIC running at 6KHz and it is running the other portions of my program okay. I have just not yet been able to think of a way to use the PIC timers to confirm that I am getting a transition on 1 input while I am also monitoring other inputs. I need to see that the input has changed within a 3 or 4 second window. It seems like it should be simple but I am not used to this type of timer. I am used to a timer that I could start and then reset with each transition so that the timer does not time out. If it does time out I would go to a fault handling routine. I need this timer running in the background while I am checking other inputs. I am sure it can be done I just haven't worked with PIC's before.
It may seem a lot harder than it actually is.
Try this. We're using Timer0 configured as a counter. When your encoder
makes a transition on RA4/TOCKI (Timer0 clock input pin), it increments
the Timer0 count.
Real simple. Runs in the background all on its own, etc,,.
Timer0 configured as a counter can count your encoder transitions in theCode:TRISA.4 = 1 ' RA4/T0CKI = input to TMR0 counter TRISB.0 = 0 ' RB0 = output for LED CMCON = 7 ' All digital ' Assign prescaler to WDT for 1:1 prescale on TMR0 ' TMR0 clock will be from your external input on RA4/T0CKI ' Increment on high-to-low transitions OPTION_REG = %00111000 ' If you prefer, then increment on low-to-high transitions ' OPTION_REG = %00101000 Main: TMR0 = 0 ' Clear TMR0 count before start Loop: WHILE TMR0 = 0 ' Wait for high-to-low transition WEND ' on RA4/T0CKI PORTB.0 = 1 ' LED on to indicate transition seen PAUSE 500 PORTB.0 = 0 ' LED off GOTO Main ' Start over END
background, and your main code can do whatever else it needs to in the
mean time.
You can set it to increment on high-to-low or low-to-high transitions by
flipping a single bit in the OPTION register.
Just look in your datasheet at the OPTION register & Timr0 sections for
how/why it works. It's really simple once you tinkered with it a bit.
Bruce, thanks for the idea. Your idea would need some adjusting to make it run in the background in my application, but it has got me to thinking about using the timer as a counter and setting it just a couple of counts from overflowing and then my program will need to see it overflow because of the transitions or else jump to a fault routine. I am just used to the smooth operation of timers and counters in PLC programming and the PIC timers just seem awkward to use.
Bookmarks