Hi all,
I'm using an HC908GP32 as an engine controller and have been stumped by what I thought should be an easy thing. I want to generate a single pulse width for fuel injector control using Tim1 CH0 for injector 1, and CH1 for injector 2. Below is the code I'm using to initialize Port D, the Tim1 timer, the calling code for inj1 and the CH0 interrupt service routine. For some reason I'm not getting an interrupt for either channel. Any help would be greatly appreciated. Here' my code:
Update:
I've made some progress. I kept trying different combinations for the TIM1 set up and finally got the correct one. I don't know why it works, but it works. Here it is:
Another update. After a lot of blood sweat and tears I think I have things figured out. Here is my TIM2 set up:
mov #%00110011,t2sc
mov #%FF,t2modh
mov #%FF,t2modl
mov #0T,t2ch0h
mov #100T,t2ch0l
mov #%11010100,t2sc0
mov #$00,t2ch1h
mov #$00,t2ch1l
mov #%00010000,t2sc1
mov #%00010011,t2sc
And for TIM1:
mov #%00110011,t1sc
mov #%FF,t1modh
mov #%FF,t1modl
mov #%00010000,t1sc0
mov #%00010000,t1sc1
mov #%00010011,t1sc
I'm still hunting bugs in the ISRs, but they appear to be functioning as they should.
After validating the code, I see some instructions that I would like to understand.
I see that you enabe the interruption by using the command mov #%01000000,T1SC0, after more setup commands you disable the same interruption by using bclr CHxIE,T1SC0, which means that the interruption will only be active during that setup procedure, right?
Also, I see that you are not using the CLI for general interruptions. Can you please try using it?
Hi Itzzamna,
So sorry about my late reply, I didn't get any e-mail notification.
In the set up procedure, after I have set things up, I disable the interrupt until I am ready to use it. I enable it again in the code at the time that I have the output compare values set and want to enable the interrupt. I think that's the correct way to do it.
I'm in the process of setting up a development board to test my code and should have it ready in a day or so. When it's up and running I will try your suggestion and get back to you as soon as I can. Thanks for taking the time to reply.
Robert
Well, I'm not doing too good with this. I set up another board just to experiment with coding just so I know that there would be nothing in my main code that would be there to cause issues. I think there is something wrong with the way I am setting up Tim1. Probably because I am not completely clear on how to do this for what I want it to do.
This is what I want it to do:
I have Port D4 set up as an output for Inj1. Port D5 is set up as an output for Inj2. Both are hardware inverted.
I have Tim1 set up as a free running counter. I have both Ch0 and Ch1 set up as output compare and the pins are under port control. I want Ch0 to control Inj1 and Ch1 to control Inj2. In my program when I get an input signal that it is time to energize Inj1 for a particular pulse width, I will get a time stamp of the Tim1 counter, add the pulse width to it, save these values to the T1CH0H;T1CH0L registers, Clear the Inj1 pin on Port D to start the injection and and enable the interrupt. In the Tim1 Ch0 ISR I will disable the interrupt and set the Inj1 pin of Port D to terminate the injection. I'll use the same procedure for Inj2.
Here is how I have things set up: