Hello All,
I'm new to PICAXE but I've written several PBP programs in the past. I'm working with Tracecom to help someone on another forum with a project. The other member doesn't plan to get into uC's much but wants the ability to modify the code so a PICAXE seemed like the ideal choice.
I've written the code as I would have for PBP, with the exception of adding a subroutine to bit-bang the SPI data to a MAX7221. While everything appears to work swimmingly, the timing is off - 10 seconds of countdown requires 15 seconds or more on the display.
In researching this further on this forum, I believe part of the problem is the PICAXE is taking more time than I realized to run the code because of the BASIC interpretation (vs. compiled code that I'm used to working with).
I didn't realize the frequency could be increased on the fly with the setfreq command. I gave that a shot and increased the frequency from 4MHz to 32MHz, the maximum frequency allowed on the 20M2 chip I'm using. This helped immensely, but when tested with a 60 second countdown, actual time was ~62 seconds. Not bad, but the timer could be set up to 99 minutes, so I'd really like to get the timing as close to spot on as possible.
I've attached my code and schematic. Code was too big to post in body of post.
I'm using the button commands in a subroutine and checking them during the countdown. When commented out, a 60 second countdown takes ~61 seconds. I wonder if it would be better set up the buttons as interrupts?
Tracecom has suggested using a 20X2 and I tried rewriting the code to use the SPIOUT command, but display only shows the all segments on test and stays there though the program continues to run (evident by the flashing LEDs). In reading the manual further, the SPIOUT command does the same thing as the bit banging routine I use for the 20M2, so I suppose if it did work, the timing would be about the same. Tracecom brought up the HSPIOUT command which uses a hardware SPI, so I'll give that a shot too. I am hoping to get away with the 20M2 if possible though.
I found a great post by Marks whose done a project very similar to what we are trying to accomplish which does not require a MAX7221, so if all else fails, we may use that (http://www.picaxeforum.co.uk/showthread.php?16020-20X2-4-digit-7-segment-Countdown-timer&highlight=countdown+timer).
Any insight or advice is greatly appreciated. Thank you.
I'm new to PICAXE but I've written several PBP programs in the past. I'm working with Tracecom to help someone on another forum with a project. The other member doesn't plan to get into uC's much but wants the ability to modify the code so a PICAXE seemed like the ideal choice.
I've written the code as I would have for PBP, with the exception of adding a subroutine to bit-bang the SPI data to a MAX7221. While everything appears to work swimmingly, the timing is off - 10 seconds of countdown requires 15 seconds or more on the display.
In researching this further on this forum, I believe part of the problem is the PICAXE is taking more time than I realized to run the code because of the BASIC interpretation (vs. compiled code that I'm used to working with).
I didn't realize the frequency could be increased on the fly with the setfreq command. I gave that a shot and increased the frequency from 4MHz to 32MHz, the maximum frequency allowed on the 20M2 chip I'm using. This helped immensely, but when tested with a 60 second countdown, actual time was ~62 seconds. Not bad, but the timer could be set up to 99 minutes, so I'd really like to get the timing as close to spot on as possible.
I've attached my code and schematic. Code was too big to post in body of post.
I'm using the button commands in a subroutine and checking them during the countdown. When commented out, a 60 second countdown takes ~61 seconds. I wonder if it would be better set up the buttons as interrupts?
Tracecom has suggested using a 20X2 and I tried rewriting the code to use the SPIOUT command, but display only shows the all segments on test and stays there though the program continues to run (evident by the flashing LEDs). In reading the manual further, the SPIOUT command does the same thing as the bit banging routine I use for the 20M2, so I suppose if it did work, the timing would be about the same. Tracecom brought up the HSPIOUT command which uses a hardware SPI, so I'll give that a shot too. I am hoping to get away with the 20M2 if possible though.
I found a great post by Marks whose done a project very similar to what we are trying to accomplish which does not require a MAX7221, so if all else fails, we may use that (http://www.picaxeforum.co.uk/showthread.php?16020-20X2-4-digit-7-segment-Countdown-timer&highlight=countdown+timer).
Any insight or advice is greatly appreciated. Thank you.
Attachments
-
46 KB Views: 30
-
Converting A Traffic Light Into A Timer Code Rev 1i - 32MHz & pause compensated, reduced check t.bas15.2 KB Views: 12