YesDo you want one thing to happen at 30, then a second at 20 counts later? And then repeat?
I did not understand how you did the calculation? What value have to load into the counter register?My current project does that. Pick a common denominator, in your case, 10 counts. Then do something after the first 3 interrupts, then after 2 do the other, and so forth.
If you want an interrupt on the 10th count, load the TMR0 register with 246; if after the 10th count pre-load with 245 as described in post #2.Yes
I did not understand how you did the calculation? What value have to load into the counter register?
I'm just taking the hypothetical situationIf the counter is 8 bits, then the maximum count is 255.
If you want to count for 30 cycles, then subtract 30 from 256.
256 - 30 = 226
Preset the counter to 226. The counter will overflow after 30 counts.
As I said it's hypothetical situation. This question is just to clear conceptsBTW, if you expect to see 10 counts on an LED, it will probably not be visible.
I don't understand that question. Your will interrupt at every 10 counts. Then in the ISR determine whether it is the 3rd time (30 counts) or 2nd (20 counts). Of course, your code must start at 3 interrupts, then accept the second interrupt, then the third, and so forth. Not hard to do in Assembly. In C, I have no clue.But if first interrupt service routine take 15 counts time, Will second interrupt generate at 236.
If first interrupt happen and it is doing its job, can another interrupt be active during this time?I don't understand that question.
Not with an enhanced mid-range device like the 12F1840. There is no ability to prioritize interrupts. If you are in an ISR, another interrupt cannot interrupt. BUT, another interrupt flag (IF) can occur that will produce an interrupt immediately on exiting the first interrupt. The 18F's provide for priorities, but that may be more bother than it is worth for simple work.If first interrupt happen and it is doing its job, can another interrupt be active during this time?
You do not need two different interrupts. THINK about it. What if you have an interrupt after two rollovers and another after three rollovers. How will the first know that the second type is yet to come? An MCU cannot see into the future. The problem as you stated it does not require that, but it does require discipline. There will be first a 30-count process, then a 20-count process, then a 30-count process and so forth. It is basically no different than flashing an LED on for 30 us, off for 20 us, on for 30 ms and so forth.Interrupt 1
Do job 1
Interrupt 2
Do job 2
The first interrupt has been generated and he is also doing his work in ISR. In the meantime, can second interrupt happen?
I have read many old threads and they are providing me a great help. I think I am not a stage where I can do anything practical don't know basics so i want to clear basics.If you want to do something different, please describe.
Do you happen to know a user @Gajyamadake? He asked similar questions. My suggestion to you, and don't take it lightly, is to get the processor we are discussing, program it, and see what happens with it in real life or simulation.
Learning to program interrupts is not basic. This is beyond basics.I have read many old threads and they are providing me a great help. I think I am not a stage where I can do anything practical don't know basics so i want to clear basics.
Yes, I want to buy a physical ARM board in which I can practice for the automotive domain. I'm not a very good guy in programming but I can manage. I have studied C programming.Learning to program interrupts is not basic. This is beyond basics.
Get an MCU, an IDE and start programming. Flash an LED without copying someone else's code.
That has been told to you at least twice by me. More by others. What do you still not understand?I am having hard time to understanding the microcontroller's peripheral. For example, I do not know which registers should be used for timer interrupt and why and which bit should be set . That's why I asked you to see post #26. I want to see how you find out required information in the datasheet
;code
list p=12f1840 ; list directive to define processor
#include <p12f1840.inc> ; processor specific variable definitions
errorlevel -302, -305
list st=off
radix dec
__CONFIG _CONFIG1, _FOSC_ECL & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
cblock 0x20
toggle
endc
org 0x0000
bra Start
;*****************************INTERRUPT SERVICE ROUTINE************************
org 0X0004 ;ISR checks status of toggle,0, branches to
;appropriate subroutine, toggles between 20
;and 30 counts.
Alternate
movlw 1
xorwf toggle,f ;set toggle for next interrupt
btfss toggle,0
bra Do20 ;alternate procedure after 20 counts
bra Do30 ;goes to Do30 on first interrupt
Do20
;<insert code for Do20>
movlw 256-30 ;calculate counts for Do30
bra ExitISR
Do30
;<insert code for Do30>
movlw 256-20 ;calculate counts for Do20
ExitISR
bcf INTCON,TMR0IF ;clear interrupt flag
movwf TMR0 ;pre-set TMR0 for next period
retfie
;*********************************END OF ISR***********************************
Start
movlb 1 ;setup MCU
movlw b'01101000'
movwf OSCCON ;OSCCON = 4 MHz
movlw b'00001000'
movwf OPTION_REG ;TMR0 = system clock,no prescale
movlb 0
movlw b'10100000'
movwf INTCON ;enable TMR0 interrupt,clear TMR0IF
clrf toggle ;
movlw 256-30 ;calculate conts for Do30
movwf TMR0 ;first period is 30 counts
nop ;idle here
bra $-1 ;idle here
end
clrf toggle
; movlw 256-30 ;calculate conts for Do30
; movwf TMR0 ;first period is 30 counts
movlw b'10100100'
movwf INTCON ;enable TMR0 interrupt,clear TMR0IF
It seems that the PIC microcontroller would be better to start at beginning because a lot of information is available on the internet about it. Here also so many peoples discuss about PIC microcontroller. I would also start with suitable PIC microcontroller.You cannot compare PIC with ARM in any reasonable fashion. They are very different architectures with hundreds of different chip models to compare.