Re: CLOCK CALCULATIONS IN PIC12F675
Well first, the 12F675 does not have hardware PWM. It does have a Timer1
and Comparators, but no PWM. I can explain the functions of the bits in
T1CON, but that won't help the PWM situation, or more precisely, the lack
Secondly, you say you want TON = 10% and TOFF = 90%. What exactly is 'T'?
Lastly, what exactly are you trying to accomplish with this program?
Let me know what you want to do from here.
i have selected the internal clock of 4 MHZ but i don't know
how to calculate the word in T1CON in my program for pwm.
PLEASE CAN U BRIEF ME WITH THE INSTRUCTION CYCLES,TIME ELAPSED AND
DUTY CYCLE? i have to write a value into T1CON BUT I AM NOT ABLE TO
CALCULATE......TON% AND TOFF% OF T, FOR LOW BATTERY CONDITION
AND VICE VERSA FOR HIGH BATTERY CONDITION.PLEASE TEACH ME THE WHOLE
CONCEPT BECAUSE ITS NOT VERY CLEAR
So with a 4MHz system clock the timers are clocked with a 1MHz
clock. This gives 1 microsecond per count.
What is the sum of TON and TOFF you are trying for (in time not
percentages)? One second total? Two seconds total??
TMR1 will control the on time and TMR0 will control the off time.
HIGH BATTERY, TON = 90% and TOFF = 10%.
LOW BATTERY, TON = 10% and TOFF = 90%.
TMR1 is 16 bits wide. TMR0 is 8 bits wide.
Assume a 1 second display cycle rate then:
HIGH BATTERY = TON = 90% = 900,000 microseconds and TOFF = 10% 100,000 us.
LOW BATTERY = TON = 10% = 100,000 us and TOFF = 90% 0,000 us.
Both of these values are out of the timers ranges.
You could use the prescalers to get the times closer but not exactly
what would be needed for a 1 second display cycle. Extending the
timers in software would provide a better fit.
Or just extend the counters in software and not use the prescalers.
AN863 has an example of exending timers. TMR0 is extended to a 16
You can see that the LED display cycle rate you want really drives
what you need to do to accomplish your goal.
Be sure to save the OSCCAL value as described in the data sheet
wold be my choice). Set it up to interrupt at 1 mS intervals and
then just count ticks. for an 8 bit timr (tmr0), you would use 5 as
the start and a prescalar of 4 on a 4 mhz machine. 900 for 90%, 100
I've used the following concepts for timing that work pretty well for
me: timer ISR simply decrements a memory location. The main loop
sets the timer count and then waits for it to go to zero.
You could prescale at higher values to get approximately 10mS
interrupts and thus just do single byte math but you will be slightly
off. For example prescale by 64 (option reg Ps2:Ps0 of 101) and use
99 (255-156) as the tmr0 value to get a 9.984 mS period. For most
apps this would be close enough (.16% off).