Page 1 of 1

rb0/int

Posted: Fri Sep 14, 2007 1:43 pm
by saschech@gmx.de
Hallo

I work with trm0int > timer0_int macro .......

it works ok.

only portb-0 is nc. so i want go this way.
I add rb0_risig edge > macro b0_int = set flagx
I add rb0_falling edge > b0_int = set flagx


in the main-menue i want reset flagx in the makro rb0_int_is

my problem the flagx alltim set??????

can you help me?

regards wolfgang

rb0_int

Posted: Wed Sep 19, 2007 11:38 am
by saschech@gmx.de
Hallo

To day i show with the mc-debugger for this problem.
I found out,without interrupt on portb 0 each time it stoop
on the breakpoint in my rb0_int macro.Itest it with falling and
rising edge....it is the same.
Is these a mistake of my ???? please give me a answer.

thanks wolfgang

Posted: Wed Sep 19, 2007 1:22 pm
by Steve
Please send your program to us (support@matrixmultimedia.co.uk) and we'll have a look.

Posted: Wed Sep 19, 2007 1:22 pm
by Benj
Hello Wolfgang

I think that if you want to detect both edges you must do the following.

1) start the interrupt to detect the rising edge
2) when interrupt starts
3) disable the rising edge interrupt
4) start the interrupt to detect the falling edge
5) when interrupt starts
6) disable the falling edge interrupt

alternativley you can use this line of C code to swap between rising and falling edge detection. Both interrupts will trigger the same macro.

set_bit (option_reg,6); //Interrupt on rising edge

or

clear_bit (option_reg,6); //Interrupt on falling edge

rb0_int

Posted: Wed Sep 26, 2007 1:16 pm
by saschech@gmx.de
Hallo Steve

I send you the code at 19.09.07........


I change on my board pic 18F4620:
port rb0_pins rb1 to rb3 = free >> rb0 = int_switch
port rb4 = output
the rb0_int works ok.

after this i input steep by steep my ather programcode
and after i input the Komponent-Makro "Sample_ADC(0)"
i have the same effect , alltime turn into interrupt_routine rb0_int .

What can i make in case of this?
I hope jou give me a answer.

Thanks wolfgang

Posted: Wed Sep 26, 2007 4:58 pm
by Steve
Hello Wolfgang,

Ben received your email on the 19th. I don't know whether his reply on this forum thread was sent after receiving your code because he is not at work at the moment.

When he comes back to work, I will ask him to reply to you.

rb0_int

Posted: Wed Sep 26, 2007 7:24 pm
by saschech@gmx.de
Hallo Steve


My new replay Posted: Wed Sep 26, 2007 12:16 pm
show a new problem with the int on rb0_int.

In mycode i kill all Komponent-Makro "Sample_ADC(0)"
and the programm works ok.I put in a op_amp in, it works also ok,
but i think it is no a solution.I hop you can help.

Regards wolfgang

Posted: Mon Oct 01, 2007 9:31 am
by Benj
Hello Wolfgang

Please can you send me your new code. I will see why the ADC is not working.

rb0_int

Posted: Mon Oct 01, 2007 1:02 pm
by saschech@gmx.de
Hallo Benj

Ok i send the new code.
but the acd(0) is working ; the problem is,
without a int on portb0 the program go into
the int_macro each time .after i delete the
macro SampleADC the int is working ok.
It is the same efekt as i work with portb......

Regards wolfgang

rb0_int

Posted: Fri Oct 05, 2007 4:47 pm
by saschech@gmx.de
Hallo Benj

I hope you have received my new mail at 02.10.2007.

I have build a small c-code for acd[0]sample and read back
with the acd(0)byte macro,
three lines into my orginal code with rbo_int.All it works correctly ,
so i think there is a fault in the macro.
In expectation for a answer

Regards wolfgang

rb0_int

Posted: Wed Oct 10, 2007 10:31 am
by saschech@gmx.de
Hallo Benj,Steve

Why I hear nothing about my problem?

Regards wolfgang

Posted: Wed Oct 10, 2007 2:16 pm
by Benj
Hello Wolfgang

Sorry for the delay.

I think I have found the cause of your problem. The ADC Sample routine converts all of the ADC pins to analogue. The interrupt pin B0 is included in this so it stops functioning as a digital input. You can change this in your FCD file for your PICmicro by opening the 18F4620.FCD file and changing the following line.

Code: Select all

ADCCapture="char ta, tb, te, cnt;\nadcon1 = 0x00;\nadcon2 = 0x03;\nta = trisa;\ntb = trisb;\nte = trise;\n#if (%a == 0)\n  trisa = trisa | 0x01;\n#endif\n#if (%a == 1)\n  trisa = trisa | 0x02;\n#endif\n#if (%a == 2)\n  trisa = trisa | 0x04;\n#endif\n#if (%a == 3)\n  trisa = trisa | 0x08;\n#endif\n#if (%a == 4)\n  trisa = trisa | 0x20;\n#endif\n#if (%a == 5)\n  trise = trise | 0x01;\n#endif\n#if (%a == 6)\n  trise = trise | 0x02;\n#endif\n#if (%a == 7)\n  trise = trise | 0x04;\n#endif\n#if (%a == 8)\n  trisb = trisb | 0x04;\n#endif\n#if (%a == 9)\n  trisb = trisb | 0x08;\n#endif\n#if (%a == 10)\n  trisb = trisb | 0x02;\n#endif\n#if (%a == 11)\n  trisb = trisb | 0x10;\n#endif\n#if (%a == 12)\n  trisb = trisb | 0x01;\n#endif\nadcon0 = 0x01 | (%a << 2);\ncnt =0;\nwhile (cnt <40) cnt++;\nadcon0 = adcon0 | 0x02;\nwhile (adcon0 & 0x02) ;\ntrisa = ta;\ntrisb = tb;\ntrise = te;\nadcon1 = 0x0f;\nadcon0 = 0x00;\n"
to this

Code: Select all

ADCCapture="char ta, tb, te, cnt;\nadcon1 = 0x03;\nadcon2 = 0x03;\nta = trisa;\ntb = trisb;\nte = trise;\n#if (%a == 0)\n  trisa = trisa | 0x01;\n#endif\n#if (%a == 1)\n  trisa = trisa | 0x02;\n#endif\n#if (%a == 2)\n  trisa = trisa | 0x04;\n#endif\n#if (%a == 3)\n  trisa = trisa | 0x08;\n#endif\n#if (%a == 4)\n  trisa = trisa | 0x20;\n#endif\n#if (%a == 5)\n  trise = trise | 0x01;\n#endif\n#if (%a == 6)\n  trise = trise | 0x02;\n#endif\n#if (%a == 7)\n  trise = trise | 0x04;\n#endif\n#if (%a == 8)\n  trisb = trisb | 0x04;\n#endif\n#if (%a == 9)\n  trisb = trisb | 0x08;\n#endif\n#if (%a == 10)\n  trisb = trisb | 0x02;\n#endif\n#if (%a == 11)\n  trisb = trisb | 0x10;\n#endif\n#if (%a == 12)\n  trisb = trisb | 0x01;\n#endif\nadcon0 = 0x01 | (%a << 2);\ncnt =0;\nwhile (cnt <40) cnt++;\nadcon0 = adcon0 | 0x02;\nwhile (adcon0 & 0x02) ;\ntrisa = ta;\ntrisb = tb;\ntrise = te;\nadcon1 = 0x0f;\nadcon0 = 0x00;\n"
The difference being

Code: Select all

adcon1 = 0x00; //All AN Pins converted to analogue
is changed to

Code: Select all

adcon1 = 0x03; //All AN Pins converted to analogue except RB0
if you are still having problems then try adding a C code icon to the main loop of your program with the following code.

Code: Select all

trisb = trisb | 0x01;
After doing this edit you will not be able to take analogue readings from pin AN12 RB0.

rb0_int

Posted: Thu Oct 11, 2007 9:53 am
by saschech@gmx.de
Hallo Benj

100 points!! After i change the line it works ok.Thanks

Think i right,if i work with the ather int_pin on rb.... i must do
the same ( with other value adcon1)

Is this also the point for the thame effekt ,if i work with the
out macro on portb1 to portb3?

Regards wolfgang

Posted: Thu Oct 11, 2007 10:40 am
by Benj
Hello Wolfgang

if you want to use the INT1 and INT2 on RB1 and RB2 respectively then you can change the line in the FCD file to this.

Code: Select all

ADCCapture="char ta, tb, te, cnt;\nadcon1 = 0x07;\nadcon2 = 0x03;\nta = trisa;\ntb = trisb;\nte = trise;\n#if (%a == 0)\n  trisa = trisa | 0x01;\n#endif\n#if (%a == 1)\n  trisa = trisa | 0x02;\n#endif\n#if (%a == 2)\n  trisa = trisa | 0x04;\n#endif\n#if (%a == 3)\n  trisa = trisa | 0x08;\n#endif\n#if (%a == 4)\n  trisa = trisa | 0x20;\n#endif\n#if (%a == 5)\n  trise = trise | 0x01;\n#endif\n#if (%a == 6)\n  trise = trise | 0x02;\n#endif\n#if (%a == 7)\n  trise = trise | 0x04;\n#endif\n#if (%a == 8)\n  trisb = trisb | 0x04;\n#endif\n#if (%a == 9)\n  trisb = trisb | 0x08;\n#endif\n#if (%a == 10)\n  trisb = trisb | 0x02;\n#endif\n#if (%a == 11)\n  trisb = trisb | 0x10;\n#endif\n#if (%a == 12)\n  trisb = trisb | 0x01;\n#endif\nadcon0 = 0x01 | (%a << 2);\ncnt =0;\nwhile (cnt <40) cnt++;\nadcon0 = adcon0 | 0x02;\nwhile (adcon0 & 0x02) ;\ntrisa = ta;\ntrisb = tb;\ntrise = te;\nadcon1 = 0x0f;\nadcon0 = 0x00;\n"
This will disable the analogue input channels AN8 through to AN12.

The change in this case is

Code: Select all

adcon1 = 0x07; //Enable AN0 - AN7 as analogue inputs
Using an output will be alright as outputs are unaffected by the state of the analogue / digital changes.

Posted: Thu Oct 11, 2007 10:43 am
by Steve
A "cleaner" fix for this chip might be to change the adcon1 to "adcon1 = 14-%a;"

I've asked Ben to look into this and report here.

If this approach works, we will modify every FCD file so that it uses a similar approach.

Posted: Thu Oct 11, 2007 10:52 am
by Benj
Yes this fix would do the following job.

Sampling an ADC channel would convert that particular channel and all other channels beneath it to analogue.

For example sampling AN8 would convert AN0 - AN8 to analogue. This means that the higher end channels are still available.

One word of caution when using this is if you were sampling AN9 then AN8 which is connected to INT2 would also be converted to analogue which would disable the interrupt while the sampling process is taking place.