I'm still trying to develop a clock control program. I want it to run in a loop. The input is a 1 minute square wave. At every 30 second positive transition it should run subroutine A . At every 1 minute negative transition it should run subroutine B. Each subroutine should run only once and then return to the loop. Attached is my code. Instead of running only once, one subroutine runs continuously and the other runs once per period.
I'm using the Microchip Low Pin Count Board with MPLAB X and PICkit 2.
'code for microprocessor version of antique-clock-modification
'v2.0 tests code for identifying pos/neg transitions on CLKIN
'Reginald Neale April 2015
#chip 18F14K22, 4
#define CLKIN PORTA.5
#define LIGHT PORTC.1
Dir CLKIN In
Dir LIGHT Out
START:
NEWCLK = CLKIN
CHGCLK = NEWCLK # OLDCLK & OLDCLK
IF CHGCLK = 0 THEN
GOSUB BELL
END IF
IF CHGCLK = 1 THEN
GOSUB CHIME
END IF
OLDCLK = NEWCLK
GOTO START
SUB BELL
LIGHT = 1
WAIT 500 ms
LIGHT = 0
WAIT 500 ms
END SUB
SUB CHIME
LIGHT = 1
WAIT 250 ms
LIGHT = 0
WAIT 250 ms
LIGHT = 0
END SUB
END
Last edit: Anobium 2015-04-08
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A few questions but these questions will help you resolve the isssues
What is expected from 'CHGCLK = NEWCLK # OLDCLK & OLDCLK'? Is this simply and assignment of CHGCLK with the value of NEWCLK?
Sub BELL lasts for ~1000ms. This longer that two transitions therefore this will miss transitions.
Sub CHIME for ~500ms therefore this get called twice and then probably miss the next transition because everything will take a few clock cycles (a few nano seconds [others can tell the actually timing]).
I think you need to use an interrupt. An interrupt would detect the state changes on CLKIN and then you can deal with this change of state when it happens. But, what do want to do in between the state changes? I think I need some description/pseudo code to help me understand to recommend a way forward.
:-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Anobium. Sorry for the uncommented code. I had trouble copying it and somehow it was not even formatted.
CLKIN is a one-minute 50% duty cycle pulse, so there are 30 seconds between positive and negative transitions. That leaves plenty of time to run each subroutine once.
The CHGCLK code is copied from someone else's program - the intention is for CHGCLK to equal 1 only when CLKIN goes from low to high.
I experimented with using an interrupt, but I'm probably don't understand how to do it The list of valid events for triggering interrupts is not large. An interrupt on PORTA for instance, will call the same subroutine for both low to high and high to low transitions. I want separate subroutines for each transition.
I hope this provides enough additional information to make the problem understandable.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Evan, can I run the above demo file on my LPC board by just changing #chip to 18F14K22 and changing PORTB.0 to PORTA.2?
Thanks for the LPC board demo header titles you listed below. I entered them in the search discussion box but didn't find the demos.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
And, if you want them. I have a few demonstrations based on the Low Pin Count Board for 18f and 16f. These both use interrupts to achieve the LED management.
The header for the demos is shown below:
'''This program supports the Low Pin Count Demo Board from Microchip.
'''This works with the PICkit™ 2 and PICkit™ 3 Microcontroller Programmer.
'''The demonstration is to help the user get up to speed quickly using Microchip microcontrollers.
''':
'''The demonstration program will blink the four red lights in succession.
'''Pressing the Push Button Switch, labeled SW1, and the sequence of the lights will reverse.
'''Rotate the potentiometer, labeled RP1, and the light sequence will blink at a different rate.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Evan. I watched the video, downloaded the PICkit 3 application and installed it. Nicely done interface, very user-friendly.
The application says it imported the hex file and programmed the 18F14K22 Demo successfully but all four LEDs are on continuously no matter what the pot setting. I'm wondering about the difference between the two versions of the LPC board. In the demo program, it appears that the button is set on PORTA.3, and I have the PICkit 3 Low Pin Count board, which moves the button to PORTA.2. So I tried to edit the demo file but that didn't seem to make any difference. I tried an older simpler program file that had worked with MPLAB and that worked OK, so I'm thinking it's a problem with the demo file. Any ideas?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Evan. I watched the video, downloaded the PICkit 3 application and installed it. Nicely done interface, very user-friendly.
The application says it imported the hex file and programmed the 18F14K22 Demo successfully but all four LEDs are on continuously no matter what the pot setting. I'm wondering about the difference between the two versions of the LPC board. In the demo program, it appears that the button is set on PORTA.3, and I have the PICkit 3 Low Pin Count board, which moves the button to PORTA.2. So I tried to edit the demo file but that didn't seem to make any difference. I tried an older simpler program file that had worked with MPLAB and that worked OK, so I'm thinking it's a problem with the demo file. Any ideas?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think you are correct about the board differences. Because if you comment out the line 'On Interrupt PORTABCHANGE Call SetInterrupt' then all the program will do is flash the leds in sequence.
I need the schematic.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
At this URL, right at the top of the page are links to each schematic. I think the only real difference is the assignment of the pushbutton to PORTA.2 instead of PORTA.3.
Evan, I received your email but my reply to it bounced: unknown user. The URL you provided for revised demos (http://tmail.mooo.com:8090/) asked me for a username and password. I'd be glad to help with finding a solution.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm still trying to develop a clock control program. I want it to run in a loop. The input is a 1 minute square wave. At every 30 second positive transition it should run subroutine A . At every 1 minute negative transition it should run subroutine B. Each subroutine should run only once and then return to the loop. Attached is my code. Instead of running only once, one subroutine runs continuously and the other runs once per period.
I'm using the Microchip Low Pin Count Board with MPLAB X and PICkit 2.
Last edit: Anobium 2015-04-08
A few questions but these questions will help you resolve the isssues
What is expected from 'CHGCLK = NEWCLK # OLDCLK & OLDCLK'? Is this simply and assignment of CHGCLK with the value of NEWCLK?
Sub BELL lasts for ~1000ms. This longer that two transitions therefore this will miss transitions.
Sub CHIME for ~500ms therefore this get called twice and then probably miss the next transition because everything will take a few clock cycles (a few nano seconds [others can tell the actually timing]).
I think you need to use an interrupt. An interrupt would detect the state changes on CLKIN and then you can deal with this change of state when it happens. But, what do want to do in between the state changes? I think I need some description/pseudo code to help me understand to recommend a way forward.
:-)
Thanks Anobium. Sorry for the uncommented code. I had trouble copying it and somehow it was not even formatted.
CLKIN is a one-minute 50% duty cycle pulse, so there are 30 seconds between positive and negative transitions. That leaves plenty of time to run each subroutine once.
The CHGCLK code is copied from someone else's program - the intention is for CHGCLK to equal 1 only when CLKIN goes from low to high.
I experimented with using an interrupt, but I'm probably don't understand how to do it The list of valid events for triggering interrupts is not large. An interrupt on PORTA for instance, will call the same subroutine for both low to high and high to low transitions. I want separate subroutines for each transition.
I hope this provides enough additional information to make the problem understandable.
I would start with this demonstration file http://sourceforge.net/projects/gcbasic/files/Demonstration%20Files/Interrupt%20Solutions/Interrupt%20Switch%20Counter%20to%20Hardware%20Serial%20Terminal%20-%2016F886.gcb/download
This shows methods to determine the status of your input port.
Have a look and test , then, ask away.
Evan, can I run the above demo file on my LPC board by just changing #chip to 18F14K22 and changing PORTB.0 to PORTA.2?
Thanks for the LPC board demo header titles you listed below. I entered them in the search discussion box but didn't find the demos.
Get the files from here. I did not post. They will be included in the next build of GCB.
https://sourceforge.net/projects/gcbasic/files/Demonstration%20Files/Vendor%20Boards/
To answer your question . Not so easy with interrupts. Look at demos I just posted.
I tried to run the demo file. It compiled with no errors in Synwrite but wouldn't build in MPLAB. I got this list of errors:
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/regneale/Desktop/LOW PIN COUNT DEMO.X'
make -f nbproject/Makefile-default.mk dist/default/production/LOW_PIN_COUNTDEMO.X.production.hex
make[2]: Entering directory 'C:/Users/regneale/Desktop/LOW PIN COUNT DEMO.X'
"C:\Program Files (x86)\Microchip\MPLABX\mpasmx\mpasmx.exe" -q -p18f14k22 -l"build/default/production/_ext/1472/18F14K22 Low Count Demo Board - Interrupt_POT_LEDS.lst" -e"build/default/production/_ext/1472/18F14K22 Low Count Demo Board - Interrupt_POT_LEDS.err" -o"build/default/production/_ext/1472/18F14K22 Low Count Demo Board - Interrupt_POT_LEDS.o" "../18F14K22 Low Count Demo Board - Interrupt_POT_LEDS.asm"
"C:\Program Files (x86)\Microchip\MPLABX\mpasmx\mplink.exe" -p18f14k22 -w -m"dist/default/production/LOW PIN COUNT DEMO.X.production.map" -zMPLAB_BUILD=1 -odist/default/production/LOW_PIN_COUNT__DEMO.X.production.cof "build/default/production/_ext/1472/18F14K22 Low Count Demo Board - Interrupt_POT_LEDS.o"
make[2]: [dist/default/production/LOW_PIN_COUNT__DEMO.X.production.hex] Error 1
make[1]: [.build-conf] Error 2
make: *** [.build-impl] Error 2
MPLINK 5.06, LINKER
Device Database Version 1.23
Copyright (c) 1998-2011 Microchip Technology Inc.
Error - Error reading object file 'build/default/production/_ext/1472/18F14K22 Low Count Demo Board - Interrupt_POT_LEDS.o'
Errors : 1
nbproject/Makefile-default.mk:112: recipe for target 'dist/default/production/LOW_PIN_COUNT__DEMO.X.production.hex' failed
make[2]: Leaving directory 'C:/Users/regneale/Desktop/LOW PIN COUNT DEMO.X'
nbproject/Makefile-default.mk:78: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/regneale/Desktop/LOW PIN COUNT DEMO.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
BUILD FAILED (exit value 2, total time: 25s)
Also, Microchip has pulled a sneaky trick. There are two versions of the LPC Demo board and the pushbutton is connected to different ports. At this link you can see the two schematics. http://www.microchip.com/search/searchapp/searchhome.aspx?id=2&q=Low%20Pin%20Count%20Demo%20Board%20Schematic&ac=1
I have the PICkit3 version.
And, if you want them. I have a few demonstrations based on the Low Pin Count Board for 18f and 16f. These both use interrupts to achieve the LED management.
The header for the demos is shown below:
'''This program supports the Low Pin Count Demo Board from Microchip.
'''This works with the PICkit™ 2 and PICkit™ 3 Microcontroller Programmer.
'''The demonstration is to help the user get up to speed quickly using Microchip microcontrollers.
''':
'''The demonstration program will blink the four red lights in succession.
'''Pressing the Push Button Switch, labeled SW1, and the sequence of the lights will reverse.
'''Rotate the potentiometer, labeled RP1, and the light sequence will blink at a different rate.
Have a quick look at https://www.youtube.com/watch?v=O9lrQ5Bzc8U
You do not need to use Mplab for basic programming/
Thanks Evan. I watched the video, downloaded the PICkit 3 application and installed it. Nicely done interface, very user-friendly.
The application says it imported the hex file and programmed the 18F14K22 Demo successfully but all four LEDs are on continuously no matter what the pot setting. I'm wondering about the difference between the two versions of the LPC board. In the demo program, it appears that the button is set on PORTA.3, and I have the PICkit 3 Low Pin Count board, which moves the button to PORTA.2. So I tried to edit the demo file but that didn't seem to make any difference. I tried an older simpler program file that had worked with MPLAB and that worked OK, so I'm thinking it's a problem with the demo file. Any ideas?
Thanks Evan. I watched the video, downloaded the PICkit 3 application and installed it. Nicely done interface, very user-friendly.
The application says it imported the hex file and programmed the 18F14K22 Demo successfully but all four LEDs are on continuously no matter what the pot setting. I'm wondering about the difference between the two versions of the LPC board. In the demo program, it appears that the button is set on PORTA.3, and I have the PICkit 3 Low Pin Count board, which moves the button to PORTA.2. So I tried to edit the demo file but that didn't seem to make any difference. I tried an older simpler program file that had worked with MPLAB and that worked OK, so I'm thinking it's a problem with the demo file. Any ideas?
I just restest here. No issues.
My board is marked -4-01831 Rev 2 if this helps.
My board is marked 04-10002-R2
Do you a schematic for you board?
I think you are correct about the board differences. Because if you comment out the line 'On Interrupt PORTABCHANGE Call SetInterrupt' then all the program will do is flash the leds in sequence.
I need the schematic.
At this URL, right at the top of the page are links to each schematic. I think the only real difference is the assignment of the pushbutton to PORTA.2 instead of PORTA.3.
http://www.microchip.com/search/searchapp/searchhome.aspx?id=2&q=low%20pin%20count%20demo
The board is different. I will rename the demo I posted to the Pk2.
Send me a personal message and I will send you a port of the demo for your board. When we have tested we can post to the forum.
Anobium
Evan, I received your email but my reply to it bounced: unknown user. The URL you provided for revised demos (http://tmail.mooo.com:8090/) asked me for a username and password. I'd be glad to help with finding a solution.
I have send you another PM.