16F887 digital clock

(instructions, reset, WDT, specifications...) PIC12F6xx, PIC16Fxxx, PIC16F6x, PIC16F7x

16F887 digital clock

Postby pjh » Fri Nov 21, 2014 11:44 pm

Hi all

This is my first post here due to Microchip's Forum well, ergh, not 'coming through' (I couldn't upload docs!). I hope I will have a better experience here.

Intro: I've been working on developing an accurate 16F887 24 hour digital clock with a secondary chip (16F628A/ or probably 16F648A, to provide 'Westminster chimes' [Cambridge Quarters]). I'm newish to C as I recently migrated from Assembly. Several people, I know many are here, have been most helpful. The project is coming along reasonably well but there is still much to do.

I've been advised (actually by Ian. M) to come here and see what happens- sooo.

I'll try to attach the necessary 3 files- clock.txt, chimes.txt and PCB.jpg (sorry about the quality). If anybody is interested in helping me, the necessary questions I currently have are toward the end of 'clock'.

thanks in advance.

I see that I can only upload one file at a time!- ummgh; that's not great then- ogh well- clock first! Ogh- I see......

Regards

pjh
Attachments
circuit.jpg
Schematic from Diptrace
circuit.jpg (126.11 KiB) Viewed 2227 times
16F628A_chimes.txt
the 628 code
(9.86 KiB) Downloaded 69 times
16F887_clock.txt
main man
(21.85 KiB) Downloaded 67 times
pjh
 
Posts: 7
Joined: Fri Nov 21, 2014 11:29 pm
PIC experience: Experienced Hobbyist

Re: 16F887 digital clock

Postby cncmachineguy » Sat Nov 22, 2014 12:19 am

Hi pjh. I have skimmed through the clock.txt file. I am not sure I saw any specific questions, but I am pretty dense sometimes.

personally I like to use interrupts for things like the display scanning. I think if you do it may get rid of strange display things when other things happen. I may be wrong, but as I think I see it now, all timing is dependent on execution times. So if things take more or less time through the loop the display will "wiggle"

This is what I see on first blush. If you are interested I have a nice debounce routine for 8 inputs using vertical counters.
-Bert
User avatar
cncmachineguy
 
Posts: 21
Joined: Sun Nov 16, 2014 8:52 pm
PIC experience: Professional 5+ years with MCHP products

Re: 16F887 digital clock

Postby pjh » Sat Nov 22, 2014 12:25 am

Hi cncmachineguy

I appreciate your post; I am happy to debounce my (only 4) switches using 'counting' but I REALLY' would like to have some insight into using interrupts (on ?/timer1) to drive my multiplexer 'cos the ghosting is driving me nuts!

My outstanding issues are all at the very end of '887clock' under 'TODOs'. and yes you are right about 'wiggling'! [my display crashes when the chimes start up!!!!!!???]

thanks for looking
pjh
 
Posts: 7
Joined: Fri Nov 21, 2014 11:29 pm
PIC experience: Experienced Hobbyist

Re: 16F887 digital clock

Postby cncmachineguy » Sat Nov 22, 2014 1:52 am

so first the interrupts -
where do we need to start?
Are you able to use them but not sure how to implement the display,
or do you need to learn how to use them first?

I have not used C for 8 bit PIC's, but I am sure we can sort it out. Also fairly certain someone will help us get there.
-Bert
-Bert
User avatar
cncmachineguy
 
Posts: 21
Joined: Sun Nov 16, 2014 8:52 pm
PIC experience: Professional 5+ years with MCHP products

Re: 16F887 digital clock

Postby pjh » Sat Nov 22, 2014 3:32 pm

Hi Bert

Thanks for that; I was busy this morning but have been thinking about this second interrupt routine. I think the entire app needs 're-jigging'.

I had already used timer0 for the 'engine' (of the clock) so had planned on using timer1 for the multiplex driver (timer2 has no Interrupt) BUT the more I think about it, timer0 is 8 bit and timer 1 is 16, the more I am convinced that I should be using timer1 for the 'engine' and timer0 for the multiplex driver. This would immediately get rid of the complicated 'clock adjust' function; it simply wouldn't be required any longer as I could (in the 16 bit timer1), use 50,000 as my count and exit an if at a count of 20 giving me EXACTLY 1000000 matching exactly 1S.

Then I can use timer0 to count to 250 and exit an if- rollover at a count of 5 which would give me (1250) the 800Hz strobe that I am looking for.

Well, what do you think?; I'm sorry if all that is a little unclear; please just ask for clarification, if not.

I might put this up tonight on Microchip as well before I do a deal of work on it tomorrow (hopefully).

In the meantime, I've just looked at the datasheet and have written the attached (early days version) of something for timer1- It'll tell you where I am now (?) and might give us something to get chewing on.

Best Regards

pjh
Attachments
timer1.c
early thoughts for comments please
(1007 Bytes) Downloaded 82 times
pjh
 
Posts: 7
Joined: Fri Nov 21, 2014 11:29 pm
PIC experience: Experienced Hobbyist

Re: 16F887 digital clock

Postby pjh » Sat Nov 22, 2014 11:48 pm

Hi
I've been doing some work on this today and tried to introduce timer1 as well as timer0 but am having problems with interrupt conflicts- particularly- the thing won't now build as:-

Error [1375] *.* \PIC_projects\clock\main_21.11.14.c; 632. multiple interrupt functions (_tmr1_int and _tmr0_int) defined for device with only one interrupt vector
(908) exit status = 1

Now as far as I know, the 887 can handle more than one interrupt source; so there must be a fault in my code. But I've looked at all of the necessary registers and think I've covered them- any ideas please? and what is an 'interrupt vector'?

I attach tonight's update
Attachments
main_21.11.14.c
(26.16 KiB) Downloaded 69 times
pjh
 
Posts: 7
Joined: Fri Nov 21, 2014 11:29 pm
PIC experience: Experienced Hobbyist

Re: 16F887 digital clock

Postby jtemples » Sun Nov 23, 2014 12:34 am

You can only have one interrupt function on a PIC16. Within that function, you determine the interrupt source by seeing which *IF flags are set.
jtemples
Verified identity
 
Posts: 148
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products

Re: 16F887 digital clock

Postby cncmachineguy » Mon Nov 24, 2014 12:52 pm

Hi pjh, I am sorry, I completely missed that you already have an interrupt working.

If this were my toy, I would use a single ISR to keep a "beat" for me. The timing of this beat will control my display. So for instance:
set up what should be displayed in each digit outside of the ISR. then when you enter the ISR, turn off display "for ghosting" then switch to whose turn it is (digit 1-4).
Then set a flag so main knows a beat happened and get out.

Then in Main you can while (!beat){};
then when beat is set, run main. Don't forget to clear beat in main so as not to re-enter main before another beat has happened. Now the tricky part is how long is the ISR. I would play with that for what works for the display first. Next I would worry about the rest of the clock stuff.

You will need to be careful that main does not take longer than the "beat" time. If so break main into states.

Your thoughts on this approach?
-Bert
-Bert
User avatar
cncmachineguy
 
Posts: 21
Joined: Sun Nov 16, 2014 8:52 pm
PIC experience: Professional 5+ years with MCHP products

Re: 16F887 digital clock

Postby pjh » Thu Nov 27, 2014 9:44 pm

Hi jtemples

Sorry, I've been real busy. thanks for that- yeagh, I found out about 'interrupt vectors' and have read around it and (think) i understand now. I've since swaped my timers so that Timer0 runs the multiplexer and timer 1 the clock itself- triggering one second 'flags'. Its a helluva lot better but its still not what I want as i have a couple of things responding th the seconds flag and they are 'jiggering' the display- I'll get back in a week or so- ish- with some more code. Cheers
pjh
 
Posts: 7
Joined: Fri Nov 21, 2014 11:29 pm
PIC experience: Experienced Hobbyist

Re: 16F887 digital clock

Postby ric » Fri Nov 28, 2014 5:50 am

Do you really need two timers?
It would be cleaner just to run the one that clocks over faster, and get it to call the code for the slower timer every X interrupts.
My new leslie-special website (for fans of The Great Race) :)
User avatar
ric
Verified identity
 
Posts: 348
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products


Return to 14-Bit Core

Who is online

Users browsing this forum: No registered users and 1 guest