![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| I have this 16f628a running a timing critical program. It is running off the internal 4mhz oscillator. I need a clock of 30k-50khz. I was hoping to add this clock output to my program,but I can't mess up the timing. I am not sure how to do this. I know the clock output is 1mhz ,but how would i get 30k-50khz without messing up my timing. I was hoping there was an easy way. I am unfamiliar with TMR0. Can it run in the background somehow or do I have to keep checking and setting a pin to get my clock output? Thanks.
__________________ Reality | |
| |
| | (permalink) | |
| Quote:
You can use tmr2 to trigger an interrupt as it times out (the time out point can be set in a register for tmr2), and the interrupt routine toggles the output pin and resets the timer. This obviously takes some time from the main program, but you don't mention why (or how) time critical the main routine might be, nor why you want 30-40Khz?. | ||
| |
| | (permalink) | ||
| Quote:
Quote:
It is for a mouse emulator . I'm learning more about it ,but not enough to start making changes yet. The 30-40khz is for the rest of the circuit that uses modulated infrared light. The frequency is just the common frequency of infrared transmitters. Do you think the 1mhz clock would work for my infrared transmitter? I'm trying to pack everything into one pic. Thanks
__________________ Reality | |||
| |
| | (permalink) |
| You can use PWM unit of 16F628 to produce required freqency without affecting main program. You just set it up, and it will run independantly.
__________________ "I share, thus I am" Jay.slovak Read this! ICD2 Clone Best PIC/DsPIC Bootloader Read my Inchworm ICD2 review! | |
| |
| | (permalink) |
| You can use the PWM to get a 30kHz output on RB3. You set it up as follows. Code: bsf STATUS,RP0
movlw 0x1f
movwf PR2
bcf TRISB,3
bcf STATUS,RP0
movlw 15
movwf CCPR1L
movlw b'00000100'
movwf T2CON
movlw B'00001100'; enable PWM on CCP1
movwf CCP1CON; Mike. | |
| |
| | (permalink) |
| Genius! Would have never figured that out by myself. I checked it out real good to make sure it would fit but in the end it was copy and paste! I will try to fill you in on the details if my project turns out like it should. Thanks.
__________________ Reality | |
| |