interrupts

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

interrupts

Post by Xavier »

Hi guys

I'm having trouble getting my timing to work, here is what I want to do I have a count=count+1 if count is =to1 I need to have one pulse per second on the other hand if I have 90 then I need 90 pulses per second my count actually starts at 90 and ends at 120 but I may have to change that a bit. I thought that if I used a frequency of 12800000 it would work as that gives me an interrupt of 100000 but my display is not playing along, to make matters worse I can't send you the flow chart because I don't have the Internet working on my PC yet. Could you please try to explain to me how to get this to work?
I'm using a 16f877a and I have a crystal of 20Mhz

All the best
Xavier

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: interrupts

Post by Xavier »

:D Managed to get the file.

Hope that this will make more sense.

Regards Xavier
Attachments
NewMDX_X6_4.fcf
(34.45 KiB) Downloaded 314 times

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: interrupts

Post by Kenrix2 »

I have done this in the past using the UART to generate the frequencies. Maybe this method will be of some use to you. The frequency out is determined by the register pair spbrgh and spbrgl. There is a formula in the attached program on how to determine the values of that register pair to get the desired frequency. Once the values are calculated they are entered into a lookup table for each register. Although it is done for another chip operating at 4MHz you can do the math and enter the new values for 20MHz and just change the target chip. For example the value for 90Hz would change from 0x2b66 to 0xD903 and at 120Hz it would change from 0x208C to 0xA2C1.
Attachments
FreqOutExperiment.fcf
(17.7 KiB) Downloaded 306 times

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: interrupts

Post by Xavier »

Thanks Kenrix2

I had thought that perhaps the only way to do it was with a lookup table. Could you tell me why when I use an interrupt of 100, 000 the LCD stops working? Using a round number as an interrupt becomes manageable, I made up a formula for it using the interrupt frequency/1000, 000 I then took 1/pulses per second and multiplied that to the first result, that gave me the amount of interrupt counts needed to achieve the required frequency but alas the LCD stopped working.

All the best
Xavier

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: interrupts

Post by Kenrix2 »

Perhaps the high speed interrupt is affecting the timings of the communication with the lcd display. You could try using timer1 (16bit) as the interrupt source instead. Timer1's register pair (tmr1l,tmr1h) can be preloaded with specific values to obtain custom interrupt timings. Attached is an untested example that generates an interrupt every .1 seconds (10Hz) using a clock speed of 20MHz and a prescaler rate of 1:8.

For help in obtaining the timer1 register pair values, you could try doing a search for "pic timer calculator".
Attachments
Timer1_interrupt.fcf
(8 KiB) Downloaded 316 times

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: interrupts

Post by Xavier »

Thank you so much Kenrix2 you have been a great help, l have been taking a good hard look at the way that you work with interrupts and timing and have come to the conclusion that I have to find a tutorial on the subject. Any suggestions?

All the very best to you
Xavier

Post Reply