Hi,
Tq again,
can i say if i want set AN9-AN13 to digital , i need to set the register value ADCON1 = 6 ?
sry for this newbie question, still trying to learn this PIC things etc..
correct me if im wrong
thanks
Hi,
Tq again,
can i say if i want set AN9-AN13 to digital , i need to set the register value ADCON1 = 6 ?
sry for this newbie question, still trying to learn this PIC things etc..
correct me if im wrong
thanks
Hi,
That is correct.
Since you're leaving some of the pins as analog inputs I'm guessing you're going to use them as that - ie analog inputs. In that case it might be needed to set the bits 4-7 in ADCON1 properly as well. Sometimes it's easier to "see" what you're doing if you write the value in binary form, like:/Henrik.Code:ADCON1 = %10000110 'Right justified result, VDD/VSS used as Vref, AN9-13 set to digital
Hi,
tq for explaining.
Yes, actually i want to try adding 2 types of circuit protection system into my previous codes.
type 1 is basically come from outside signal called fault signal. when this fault signal is 5v, the PWM will operate in normal condition, however when fault signal is 0v PWM will stop operation (i thinking duty=0 instead of stopping the whole operation of PIC)
type 2 also from outside signal but from an op-amp. this op amp will compare the value of voltage. maximum output voltage from this opamp, i set to 3V. So when exceed 3V, the PIC will stop operation.
can you help assist what should i consider to design this kind of circuit protection in term of commands used, what should be define at PIC etc..?
thanks
photoelectric
Hi,
I'd probably handle the discrete fault signal (type 1) thru an external interrupt (PortB.0) as it will give you a fast response time. If you find that tricky and/or the response time to that input isn't very important you can simpl poll an input each time thru the main loop and stop whatever needs stopping.
As for the overcurrent (I'm guessing that's what it's for) you could possibly use the onboard comparator (look at the datasheet, section 13). It too can generate an interrupt when its output flips or you can simply poll the output directly or the interrupt flag if you want a "latching" signal.
/Henrik.
Hi,
i read the ON INTERRUPT section on PBP book and still trying to understand it.
if i want to implement an interrupt command on my codes, should i declare the interrupt in the main loop?
below is the coding for type 1 :
let say:
anything wrong with this codes?i need to write it in the main loop?Code:ON INTERRUPT GoTo faultsignal INTCON = %10010000 'Enable RB0 INTERRUPT OPTION_REG.6 = 0 'Interrupt on rising edge of RB0/INT pin Disable 'Disable interrupts in handler faultsignal: CCP1CON = %00000000 'off ccp1 INTCON.1 = 0 'Clear INTERRUPT flag Resume 'Return TO main program Enable 'Enable interrupts after handler
did really pin rb0 can detect changes from 5v to 0v using ONLY this codes?
Hi,
That looks to be correct but I haven't tried it. Obviously you have to write code in the interrupt handler to take care of whatever needs to be taken care of when it sees the signal but yes, interrupts work like that.
You declare the interrupt at the beginning of the program. Then, whenever PortB.0 goes high the execution will jump to the label you specify (Faultsignal in this case). It executes the code there and when it sees the Resume keyword it returns to where it left off.
Don't try to incorporate it in your application directly, play with it a bit first. Make a LED blink continously and have the interrupt toggle another LED so you see how it works, then move on to incorporate it in your application.
With that said ON INTERRUPT isn't the most effective of handling interrupts but I won't go into that right now. There are TONS of info on interrupts on this forum, do a little searching and reading.
hi,
OK i will play it using LED first. The port B0 that i declare says that when the fault signal detect 5V is the normal operation, when suddenly changes to 0v, port B0 automatically goes to my interrupt handler to do whatever need to be done.
So, my question is:
1. did portb0 can detect directly 5v without adding extra codes that define the values of voltages?
2. if yes, can i use pull-up resistor with push-up button to create a changes signal to the portb0 and see the interrupt works or not?
3. if not, what others method to create a changes signal to the portb0?
thanks,
photoelectric
Bookmarks