...or , how I can make SPWM without intrerupts...?
...or , how I can make SPWM without intrerupts...?
Darrel came up with a terrific piece of code for my project - have a look at this thread:
http://www.picbasic.co.uk/forum/showthread.php?t=17299
Hi,
I guess you COULD use ADCIN but it kind of defeats the purpose of the interrupt since it is a self timed command.
When using ADC interrupts you basically set the GO/DONE bit to start the converstion and the interrupt fires when the ADC conversion is done. If you then use ADCIN in the interrupt handler it would perform another, self-timed, conversion which, again, kind of defeats the use of interrupts in the first place.
The idea is to start the conversion and then either go to sleep or go do something important while the ADC does its job. The interrupt fires when the conversion is complete and you go grab the result by reading ADRESH/ADRESL register pair.
/Henrik.
Thanks Henrik. I've never done A/D conversion before other than through ADCIN but I guessed it wouldn't make sense to use in an interrupt. I'll have to do a search on 'ADRESH' to see how to read the result when I turn the trim pot dial.
I've set up and ADC interrupt using DT_INST-14 with the following handler code:
Is that right? I just need 8-bit ADC resolution (0-255)Code:' *************************************************************** ' [A/D - interrupt handler] ' *************************************************************** ADC_change: PAUSEUS 50 ' Wait for A/D channel acquisition time ADCON0.1 = 1 ' Start conversion WHILE ADCON0.1 ' Wait for it to complete WEND ADCInVal = ADRESH @ INT_RETURN
Hi,
Well, that too defeats the purpose of using the interrupt in the first place since you trig the conversion and sit around waiting for it to complete while IN the interrupt handler. You could just as well have used ADCIN in the ISR.
One thing we need to get squared away just so we're clear. Your ISR is called ADC_Change and from that I get the feeling that you might think the ADC interrupt fires when the voltage at the input changes - that's not the case. If that was already obvious to you then I appologise, I just wanted to clarify that.
You start the conversion from within your main code or possibly from another ISR, whatever. Then, instead of sitting around waiting for the duration of the conversion you go do something else or go to sleep to provide a quiet environment for the ADC. The interrupt then fires when the conversion is complete and all you need to do in the ISR is grab the result by reading ADRESH, just like you're doing now.
As you probably know using, when using DT-ints, PBP needs to do a whole lot of context saving/restoring when entering/exiting the ISR and this takes time. So it might not even be worth it using interrupts as the time taken to enter and exit the ISR could very well be longer than the ADC conversion time. I don't know for sure, and it depends, just saying..... If reading the result is all you're going to do in the ISR then you can probably get away with an ASM type handler still written in PBP which will be much quicker to get in and out of - but that's always "risky" so lets not go there untill you have something that works and does what you need.
/Henrik.
Thanks for your detailed reply, Henrik. In the past, I've just used a GOSUB in the main loop and in the subroutine call ADCIN and compare the current value to a previous value; if it's different, I use that 8-bit value to set a PWM duty cycle to brighten/dim an LED. For this project, I thought it might be more efficient to set up an AD_INT interrupt which I thought would be triggered whenever I turn the dial on the trim pot and hence slightly more efficient. I think I see now that I'm wrong in what I thought would trigger this interrupt and that I guess I have to go back to the GOSUB approach.
Bookmarks