i am allowed to use pic16f84 and 10 mhz crystal. i think this project is impossible, since i have struggled so much, but unfortunately he has a circuit doing that with pic16f84 :0
i am allowed to use pic16f84 and 10 mhz crystal. i think this project is impossible, since i have struggled so much, but unfortunately he has a circuit doing that with pic16f84 :0
thanks a lot mackrackit
that utility makes me more careful about timer. now let me review my program again
Your first post said you needed to be able to select 2 frequencies. How are they selected? If they are just hardcoded in and there is nothing in the "main", there is no need for an interrupt. You can do it all from the main routine. This will save all the time required to process the interrupt.your code would have 1 line looking for the timer overflow such as :then load 2 counters, 1 for each outputCode:while !tmr0 overflow wend
then on each overflow, decrement the freq's. when 1 reaches zeroCode:freq1 = period / timer0 freq2 = period2 / timer0
now don't forget to reload the timer unless you can set it up to just free run. You will need to play with the freq's counter numbers to "tune" the output, but I suspect you can get it right on the money.Code:if !freq then toggle output bit reload freq endif
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
hi cncmachineguy
dividing two variables by tmr0 and obtaining two periods from tmr0, it seems to work, but i think there can be some problems. for example, should we reload tmr0 with respect to which signal? for the first pulses ok but then when next period start?
program below is what you said, isn't it? thank you for advices
Code:OPTION_REG=%00000000 TMR0=0 INTCON=%10100000 main: while tmr0>=250 tmr0= 0 wend freq1= per1 / timer0 freq2= per2 / timer0 if freq1<1 then toggle a0 per1=100 else endif if freq2<1 then toggle a0 per2=200 else endif goto main
second one should a1sory
You are close to what I mean. TMR0 Should be setup as a time base, you had mentioned 8uSec in another post. So compute the reload value for TMR0 such that you get an interrupt flag at 8uSec. (hint: use PicMultiCalc to help get the values)
Next the freq values are computed by YOU and hardcoded. so if TMR0 is 8uSec, and you need a period of 800 uSec, freq will be 800/8 or freq = 100.
Your while loop just needs to check for TMR0 interrupt flag bit. You do not want to enable interrupts, but the flag will be set anyway. So as soon as the flag is set you need to do this:
I will let you work on how to actually code the above. You almost have the Freq checks correct. Put comments in your code. This will do 2 things:Code:reload the TMR clear the flag decrement freq1 &freq2 check each for zero (IF !freq1 then) this will check if freq1 = 0
1 tells others and yourself what things are doing. If you code more beyond this class, you will be VERY happy you started doing this.
2 When you comment what you think things are doing, It will make it easier to see what is wrong. Here is a for instance:
This will not work ok, the ugly is all your program will run while waiting for the timer to reach 250. Then when tmr does reach 250, you just set it back to zero. Effectively tmr0 is doing nothing for you here. I will leave it to you to try to figure out why.Code:while tmr0>=250 ' this line checks if TMR0 is greater then 250 tmr0= 0 'this line sets TMR0 to equal 0 if it is greater then 250 wend ' this is where the program jumps to when TMR0 is less then 250
BTW, I am in no way a very good teacher, so please bear with me. My goal is to give you clues and help you to understand what is going on as opposed to telling you how to do each step. Is there a deadline when you must be done?
Last edited by cncmachineguy; - 29th July 2011 at 13:53.
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
sory i am writing fast and i forget something. there is no deadline but i must submit as soon as possible.
i am going to review the program, and i will send the results , i must be careful. thanks a lot for your advices
best regards
Bookmarks