RB0 on 12F1822 PIC?

Moderator: Benj

Post Reply
conroydp
Posts: 20
Joined: Mon Apr 09, 2012 8:53 am
Been thanked: 3 times
Contact:

RB0 on 12F1822 PIC?

Post by conroydp »

Hi,

I recently developed a flowchart that I am using to calibrate an electronic speedometer to either increase or decrease the reading going to the speedometer. I originally designed the circuit using a 12F683 and made a few examples that worked 100%. However, the 8mhz CPU on the 12F683 is too slow to perform accurate calibration and I ported the flowchart to a 12F1822 with a 32Mhz processor.

I used pin 5 on the chip (12F683) to read the signals from the speedometer sensor (using the interrupt function), however, if you enable the interrupt function on Flowcode for the 12F1822 it seems to be "tied" to RB0. According to the datasheet, there is no RB0 on the 12F1822.

I would appreciate assistance in enabling the interrupt on pin 5 on the 12F1822. I have attached my Flowchart.

Regards
Conroy
Attachments
Speedo_corrector_Plus_minus20161105.fcf
(12.09 KiB) Downloaded 320 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RB0 on 12F1822 PIC?

Post by medelec35 »

Hi Conroy,
I'm fairly sure its a cosmetic thing only.
when RB0Int is selected it should work on Int (pin5 RA2)
Have you tried on hardware?
Just had a look at your flowchart and you have no configuration settings set.
you should do a 1 sec flasher before progressing.

Martin
Martin

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: RB0 on 12F1822 PIC?

Post by LeighM »

Hi,
Yes, I was just checking the datasheet too.
Flowcode and the C code refer to RB0, but as Martin mentioned, it's only a textual error,
the interrupt code just enables the external INT, which is RA2 on this device.

conroydp
Posts: 20
Joined: Mon Apr 09, 2012 8:53 am
Been thanked: 3 times
Contact:

Re: RB0 on 12F1822 PIC?

Post by conroydp »

Hi Martin and Leigh,

Thank you for your response, I have not yet tried it on hardware.

I did manage to compile successfully. I will try it tonight and post a reply.

Regards
Conroy

conroydp
Posts: 20
Joined: Mon Apr 09, 2012 8:53 am
Been thanked: 3 times
Contact:

Re: RB0 on 12F1822 PIC?

Post by conroydp »

Hi Martin,

I have tried just about everything but am unable to get the chip running. I used Test12f1822-#3.fcf from another thread to confirm hardware is operational and the PIC works. I was able to get the LED to flash on RA0.

I then replicated the chip configuration in my flowchart to no avail. I also changed to output on RA4 to output 255 instead of 1 as recommended in your earlier post. The circuit works perfectly with a 12F683 but not with 12F1822. I have checked for any potential differences between the pinouts, however they appear very similar.

So in my circuit, I have the following.

74HC14 that cleans the signal. I then use pin 5 (RA2) to read the signal coming from the 74HC14. This calls a macro that adds one to the counter.

In the main loop, I first determine whether the signal should be increased or decreased by checking the value of RA5. If RA5 reads 5V, I continue with programming to decrease the signal, if not, I enter programming to increase the signal.

After the calculations, I output the modified signal on RA4/AN3.

After programming and providing a 600Hz signal to pin 5 (RA2), I am unable to see any output on pin 3 (RA4/AN3). All I can deduce is that the interrupt is not working or the value of RA5 is not read correctly.

I would really appreciate any suggestions/recommendations.

Regards
Conroy
Attachments
Speedo_corrector_Plus_minus20161105.fcf
(12.04 KiB) Downloaded 353 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RB0 on 12F1822 PIC?

Post by medelec35 »

Hi Conroy,
First you said you wanted 12F1840 to run at 32MHz
If you look at the datasheet on page 61:
OSCCON Settings.png
(90.76 KiB) Downloaded 5658 times
You will see that if osccon bits 6 - 3 are = 1110 then internal osc will run at 32 or 8MHz depending if PLL is enabled or not respectively.
You can force the PLL to run independently of configuration settings if bit 7 of osccon is set.
If bit 7 of osccon is cleared then PLL will only be enabled if it's enabled within config settings, otherwise it will not be enabled.
Also if you look at the page 61 then you will also see that choices for internal oscillator are:

Code: Select all

31KHz  
31.25KHz
62.5KHz
125KHz
500KHz (this is the default value if osccon value is not set, so no matter what you set Clock to, oscillator will always run at 500KHz)
1MHz
2MHz
4MHz
8MHz
16MHz
32MHz
You must bear in mind that when you enter a clock speed e.g 20MHz as in your flowchart, it will not make the chip run at 20MHz.
The clock value is merely for any components that have a delay or resister value that is clock speed dependent.
E.g LCD's RS232, CAN, I2C e.t.c.
It's either an external crystal or resonator for external OSC or osccon=0xXX; value for internal oscillator that determines the osc speed.
You can either enter OSCCON value (at the very top of Main macro) in Binary by starting with 0b
Or enter Hex value See this post, by starting with 0x.
You have got:

Code: Select all

osccon = 0x78;

Code: Select all

=0b‭01111000‬ = 16MHz
Since you have
Clock Speed.png
(1.25 KiB) Downloaded 5658 times
There is a mismatch for Clock setting and actual clock speed.
My advice is set clock speed for 32MHz then set

Code: Select all

osccon=0xXX; where XX is the value that sets osc speed
to give 32MHz taking into account what I said about bit 7 of osccon.

Another issue with configuration settings is you have watchdog enabled.
If you don't enable Autoclear watchdog, then the default time for the chip to keep resetting is 18ms.
So your code won't have time to do much at all which is what you are probably experiencing!
My advice is disable watchdog (so Autoclear watchdog does not have to be enabled) until its really required.
Once that and osccon=0xXX; settings are corrected then you should have a chip that runs at 32MHz.

Martin
Martin

conroydp
Posts: 20
Joined: Mon Apr 09, 2012 8:53 am
Been thanked: 3 times
Contact:

Re: RB0 on 12F1822 PIC?

Post by conroydp »

Hi Martin,

Tx you for your comprehensive and clear explanation.

So if I understand you correctly, I need to have the following 3 settings to run at 32Mhz, starting with
osccon.JPG
osccon.JPG (35.39 KiB) Viewed 10017 times
followed by setting the speed to 32Mhz and Auto clear Watchdog in the chip configuration as below
config.JPG
config.JPG (41.1 KiB) Viewed 10017 times
As a note... it is reassuring to know that there are members on this forum like yourself. People with an abundance of knowledge and a deep understanding of the subject who is always willing and eager to assist newcomers.

Thanks again...

Regards
Conroy
Last edited by conroydp on Mon Nov 07, 2016 6:37 am, edited 1 time in total.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RB0 on 12F1822 PIC?

Post by medelec35 »

Hi Conroy,
Your welcome
I have just edited my post to make it clearer.
You must assign osccon with a value and end with a semicolon as you do with most C code commands.
If you look at the link I posted on my post above it should show you haw to assign osccon with correct value.

Also if watchdog is not required then disable watchdog from configuration settings and then you can unselected Autoclear watchdog.
Martin
Martin

Post Reply