PIC12F683 EEPROM and Internal Frequency

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times
Contact:

PIC12F683 EEPROM and Internal Frequency

Postby Speedy2k » Sat Aug 11, 2012 1:19 am

Hi, i have a little problem with a PIC12F683, i have setup a PWM to control a DC motor, i have an input pin where i receive the pulse from the hall effect sensor. I would like to spin the motor for let say 100% speed for 10 seconds and get 1 frequency sampe every second to have an average on 10 seconds. After that iw ould like to write it to the rom, I wan to do that because i don't know exactly what is the maximum Frequency the motor will generate and if my formula are ok, by doing this, i will be able to read the eeprom with my programmer and look at the value. The maximum Frequency should be around 530Hz. the motor should spin about 16000rpm and there is 2 pulse per rotation. The main problem i got is that i only have the home version of Flowchart, by the way i really love this software, but to be honest the EEPROM feature only avaible to PRO version is a real pain. Paying around 235$USD only to write to eeprom is a real problem. I think this is a feature that everybody home user and Pro user need. So the question, is there any way to write to eeprom from the C code ?

I have another question, i have read in this forum that the default setting for those chip are 4Mhz, but in the datasheet, the chip should run 8Mhz or 16Mhz, so is it possible to run it a 4Mhz or i must configure it to run at 8Mhz and if so what is the best way to do it? Thanx a lot!!

Here is the Flowchart of what i would like!
Attachments
12F683_Test_Save_FREQ_MAX.fcf
(15.64 KiB) Downloaded 157 times

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: PIC12F683 EEPROM and Internal Frequency

Postby Enamul » Sat Aug 11, 2012 3:13 pm

Hi,
I have posted here a program in FCV4 where EEPROM..read write are implemented in c code...C code is in the supplementary code are in project option..in FCV5 it is build tab...

This chip can run upto 8MHz internal clock...I configured for 8 MHz..

Code: Select all

//osccon = 0x66;  // 4MHz setting
osccon = 0x76; //8 MHz setting

You can change to whatever you like.

The program is sending EEPROM read value to all pins in porta but GPIO<3> IS EXTERNAL Mclr AND you can use this as input but not as output.so basically 5 pins are showing the LED pattern...
At the start, EEPROM is erased so value 0xFF...so all LED will be on then all off then increments every seconds...but if you switch off/on power you can see the pattern is stored in EEPROM.
Hope this will help...
ENamul
Attachments
EEPROM_C_8MHz.fcf
(6.5 KiB) Downloaded 168 times
Enamul
University of Nottingham
enamul4mm@gmail.com

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times
Contact:

Re: PIC12F683 EEPROM and Internal Frequency

Postby Speedy2k » Sat Aug 11, 2012 5:58 pm

Ok, Thanx a lot i have been able to write to EEPROM, but, any speed i set the motor to, i always get the same value in EEPROM, i am not shure where you get the FCV_COUNT variable set to write to eeprom ? And another problem is that the value writen to eeprom can be from 0 to 1200, i have read another of your post about splitting the value, but not shute if i do it right! Can you take a look at the file? Thanx a lot!
Attachments
12F683_Test_Save_FREQ_MAX.fcf
(15.64 KiB) Downloaded 131 times

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: PIC12F683 EEPROM and Internal Frequency

Postby Enamul » Sat Aug 11, 2012 6:43 pm

Hi,
I can't find EEPROM in your program where you have used that. Nothing in supplementary C code.Where you used that code? Or you want me to add that for you? Actually it will take time to check the whole code if you don't guide me what you did..I can modify last post to write integer number..
Enamul
Edit: you can write and read int data using this program concept..
Attachments
EEPROM_C_INT_8MHz.fcf
(7 KiB) Downloaded 136 times
Enamul
University of Nottingham
enamul4mm@gmail.com

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times
Contact:

Re: PIC12F683 EEPROM and Internal Frequency

Postby Speedy2k » Sun Aug 12, 2012 3:41 am

Hmm really sorry, i was shute the file i post to the forum was the updated one!! Here is the good one!

But now i got a major problem, when the program was rolling earlier today, it as just stoped working The motor have stopped. I have tried to read the PIC and nothing to do, it just don't respond at all. I have a PICKit 2 Clone that was working perfectly 1 minute before. I got this error: PICkit 2 unsupported part (ID=3FE0)

Do you know if it i fixable ? It as happen when i was testing the closed loop PWM by slowing down a wheel whit my hand.

It is the 2e chip that does that, the first one was a 12F615.

I have other in command, but they will arrive next week, is there anyway you think i can force a reset or an erase on this chip?

Thanx a lot!
Attachments
12F683_Test_Save_FREQ_MAX.fcf
(17.53 KiB) Downloaded 131 times

User avatar
Benj
Matrix Staff
Posts: 14655
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4646 times
Been thanked: 4267 times
Contact:

Re: PIC12F683 EEPROM and Internal Frequency

Postby Benj » Mon Aug 13, 2012 3:41 pm

Hello,

Sounds like the chip might have had it. Are you protecting the micro from any spikes the motor might throw out by using flyback diodes? Grabbing the motor with your hand and changing the speed or load rapidly will help to generate spikes that could fry your micro if not protected correctly.

http://en.wikipedia.org/wiki/Flyback_diode

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times
Contact:

Re: PIC12F683 EEPROM and Internal Frequency

Postby Speedy2k » Mon Sep 03, 2012 2:44 am

I still have one question Enamul, I have switched my test device to a PIC16F887, is the write eeprom and read eeprom c code in the flowchart you have posted will work with this chip ? Thanx a lor!

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: PIC12F683 EEPROM and Internal Frequency

Postby Enamul » Mon Sep 03, 2012 8:35 am

Hi,
I have modified the program to adopt in PIC 16f877a. Supplementary code is fine and can be used in any PIC with EEPROM. But the "osccon" c code has to be removed from main program. I have done that for you. I have corrected config and clock setting for you..clock needs to be 19.66MHz. But you can change that from view>project options to 4 or 10 or 20 MHz and need to change in config (chip>config>switch to expert config screen) correspondingly XT or HS or HS.
Attachments
EEPROM_C_INT_16f877a.fcf
(7 KiB) Downloaded 139 times
Enamul
University of Nottingham
enamul4mm@gmail.com

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times
Contact:

Re: PIC12F683 EEPROM and Internal Frequency

Postby Speedy2k » Mon Sep 03, 2012 1:12 pm

Thanx a lot my chip is a 16F887 and not the 877a?
Is it changing anything? Thanx

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times
Contact:

Re: PIC12F683 EEPROM and Internal Frequency

Postby Speedy2k » Mon Sep 03, 2012 5:15 pm

Ok i can confirm it is working on the 16F887 to but keep in note that you need to use all CAPITAL variable name on the C code or you get an error at compilation.

Tanx a lot!

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: PIC12F683 EEPROM and Internal Frequency

Postby Enamul » Mon Sep 03, 2012 5:20 pm

Hi,
I don't think so..you can simply swap PIC 16f877a to PIC16f887..That's it. I have just compiled the file without changing anything. It compiles fine.
Enamul
University of Nottingham
enamul4mm@gmail.com