Gate and a Capture/Compare Module is not explained much. Event on pin hi/lo change and how to count how many pulses in 1 second. To 1 MHz without calculating instruction time but counter overflows.
Chris--GCB does everything I try. I haven't tried making a composite video signal yet though with GCB,then timing would be of interest.
Last edit: stan cartwright 2017-06-06
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I just finished the first test and it was successful!
I've managed to activate pic, using a combination of 4 signals from expansion port, that feed a 4002 4input dual NOR gate, where the output is given to PortA.3 of the 16f684.
The code i used is this:
'#define BUSY PORTC.0
dir PORTA IN
DIR PORTC IN
WAIT 5 s
Do
DO WHILE PORTA.3=off
Loop
DIR BUSY OUT
SET BUSY OFF
wait 3 s
DIR BUSY IN
Loop
In theory, the "activate" signal should be always off, unless a specific input or output port command is given from amstrad's basic. When this happens, pic should react by pausing amstrad for 3 seconds (this is what Busy signal do, in reality it's the READY signal from expansion port, which is used by Amstrad's Gate Array 40010 chip to issue wait states to Z80 every micro second), and after finishing pause,i change the direction to input-high impedance state, and thus Gate array can take back control and unpause the Cpu. I've tried it with internal 8Mhz clock, and guess what... IT WORKED!
I could actually pause amstrad for 3seconds, whenever i gave an inp or out command, but ONLY to specific ports &FBD0 to &FBDF! Anything else, use of any other port, or any activity on amstrad, didn't seem to affect the circuit, it was like it wasn't connected!
Now, the second thing to do is to try to make the reaction speed of pic in less than 1micro second (because @8mHz, although pic did manage to catch the activation pulse, it's reaction took some micro seconds, and when i measured some signals from cpu, they had different values of what they should, and most probable i will not be able to read/write a byte to data bus) . So i took a 20Mhz oscilliator a couple of 22pF capacitors, and use this diagram: https://learn.mikroe.com/ebooks/wp-content/uploads/sites/3/2016/01/pic-microcontrollers-programming-in-c-chapter-03-image-151.gif?x38096
Unfortunately i didn't manage to make pic work at 20Mhz. I tried both XT and HS modes, but none seemd to work (i either got nothing or constant freeze when gave port commands from basic). I found in pic's datasheet that maybe a resistor is needed between OSC2 and crystal pin, but it doens't say anywhere waht value should i use. I never tried a pic with external clock circuit so i don't have any experience at all with it, so i would appreciate any suggestions.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When working with Microcontrollers the Datasheet can be your best friend.
Look at the PIC16F684 Datasheet (Table 3-3). This is how your crystal should be connected. I would try either 10 pf or 20 pf capacitors. I generally use 10 pF on a breadboard since the breadboard adds about 7 pF.
I have never had to use a series resistor with a PIC crystal setup. But the Datasheet shows how to connect if necessary. That same section of the datasheet also gives you the names of the MIcrochip Application Notes related to using crystals with a PIC. AN826, AN849, AN943, AN949. To get the applications note. Just Google them ... eg "Microchip AN949"
Below is a test program comfirmed to work for testing crystal operation o a 16F684. If working ok, the LED will blink at 1 Hz.
.
;; Test Crystal Operation; FCMEN = OFF prevents fallback to internal OSC; MCRLE = OFF = Programmer cannot hold chip in reset;
#Chip16F684,20
#configOSC=HS,MCLRE=ON,FCMEN=OFFDirPORTC.2OUT'// Blink at 1 HzDo Pulseout PortC.2, 500 ms Wait 500 msLoop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the info and the program william. The clock circuit is surely ok, but i used 22pF caps. So as the oscilliator circuit (crystal+2 caps) are on a small part of a prototype pcb which is connected with jumper wires to pic's OSC1, OSC2 pins, you think that maybe these add up capacitance beyond maximum allowed? Maybe i should try with 10pF as you say then?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Glad you are getting it working.The expansion port needs stuff less than 2 inches away if I remember. There's a wait for screen refresh command somewhere so I guess you disable interrupts when you access ports.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
No stan, i don't have to disable interrupts, amstrad works as usual.
First i have to learn what signals i need (and what levels should have) in order to recognize that amstrad calls an I/O port. Thankfully, it wasn't so hard thing to find: http://www.cpcwiki.eu/index.php/Connector:Expansion_port
If you take a look above, you will easily find out that combining IORQ=0 and M1=1 defines exclusively that amstrad is calling an I/O port (that's how i get rid of interrupts which also have IORQ=0 signal, but M1=0).
This is the first step. But as the Gate Array 40010 chip inside amstrad (this is the "general management" chip which controls and synchronizing everything) makes frequent calls to internal I/O ports too (mostly to 6845 CRT Chip: http://www.cpcwiki.eu/index.php/Default_I/O_Port_Summary ), we need a way to define that only when a specific port is selected, pic will react.
This was a bit more "Tricky", as i had to know the port allocation of amstrad, which fortunately, was also provided from here: http://cpctech.cpc-live.com/docs/iopord.html
A bit of studying reveald that using only two more signals (2 address bits to be more precise) , i finally managed to recognize when amstrad makes an I/O call to a SPECIFIC port! ;-)
Last edit: ikonsgr74 2017-06-08
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sounds interesting. It's ages since I used one.I vaguely remember di was cancelled by hardware polling and erasing and redrawing graphics in a frame refresh was not as viable as a bbc micro.Before cpc 464 launch 2 guys I knew set up britannia software and got a white cpc464 with hard wired ula proto type same size as the 464 hanging off the back. The guys were selling rom boxes and having problems with the expansion pcb edge not being buffered. I used maxim or summat assembler on rom and it let you write bigger programs cos the assembler wasn't in ram.
Nostalgia,sigh.
ps pic programmers used to use the parallel printer port and needed accurate timing so maybe try using that directly, Just a thought
Last edit: stan cartwright 2017-06-08
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I already did that, and worked perfect! The strobe and ready signals are the only signals provided with printer port (besides the data bits of course), but they were just enough to be able to manage communication with pic. Unfortunately amstrad's printer port, has 2 major "flaws":
First and most important, printer port is output only, you can't accept data from outside using printer port.
Secondly, data bus is 7bit, so you can't send a full byte at once, (actually you can, using software but this would be awfully slow -as you need to send half byte each time- and it requires special software on the other side too)
I'm a member of a retro computer fun club here in Greece, and we really enjoy "playing" with our beloved home micro's especially the old 8bit! ;-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Gate and a Capture/Compare Module is not explained much. Event on pin hi/lo change and how to count how many pulses in 1 second. To 1 MHz without calculating instruction time but counter overflows.
Chris--GCB does everything I try. I haven't tried making a composite video signal yet though with GCB,then timing would be of interest.
Last edit: stan cartwright 2017-06-06
I just finished the first test and it was successful!
I've managed to activate pic, using a combination of 4 signals from expansion port, that feed a 4002 4input dual NOR gate, where the output is given to PortA.3 of the 16f684.
The code i used is this:
'#define BUSY PORTC.0
dir PORTA IN
DIR PORTC IN
WAIT 5 s
Do
DO WHILE PORTA.3=off
Loop
DIR BUSY OUT
SET BUSY OFF
wait 3 s
DIR BUSY IN
Loop
In theory, the "activate" signal should be always off, unless a specific input or output port command is given from amstrad's basic. When this happens, pic should react by pausing amstrad for 3 seconds (this is what Busy signal do, in reality it's the READY signal from expansion port, which is used by Amstrad's Gate Array 40010 chip to issue wait states to Z80 every micro second), and after finishing pause,i change the direction to input-high impedance state, and thus Gate array can take back control and unpause the Cpu. I've tried it with internal 8Mhz clock, and guess what... IT WORKED!
I could actually pause amstrad for 3seconds, whenever i gave an inp or out command, but ONLY to specific ports &FBD0 to &FBDF! Anything else, use of any other port, or any activity on amstrad, didn't seem to affect the circuit, it was like it wasn't connected!
Now, the second thing to do is to try to make the reaction speed of pic in less than 1micro second (because @8mHz, although pic did manage to catch the activation pulse, it's reaction took some micro seconds, and when i measured some signals from cpu, they had different values of what they should, and most probable i will not be able to read/write a byte to data bus) . So i took a 20Mhz oscilliator a couple of 22pF capacitors, and use this diagram:
https://learn.mikroe.com/ebooks/wp-content/uploads/sites/3/2016/01/pic-microcontrollers-programming-in-c-chapter-03-image-151.gif?x38096
Unfortunately i didn't manage to make pic work at 20Mhz. I tried both XT and HS modes, but none seemd to work (i either got nothing or constant freeze when gave port commands from basic). I found in pic's datasheet that maybe a resistor is needed between OSC2 and crystal pin, but it doens't say anywhere waht value should i use. I never tried a pic with external clock circuit so i don't have any experience at all with it, so i would appreciate any suggestions.
Btw, the crystal i used is like this: http://www.shelfkey.com/prodimg/48717409.jpg
And written on it:
20.000000
HCJ-30
03/04-9C
Last edit: ikonsgr74 2017-06-06
When working with Microcontrollers the Datasheet can be your best friend.
Look at the PIC16F684 Datasheet (Table 3-3). This is how your crystal should be connected. I would try either 10 pf or 20 pf capacitors. I generally use 10 pF on a breadboard since the breadboard adds about 7 pF.
I have never had to use a series resistor with a PIC crystal setup. But the Datasheet shows how to connect if necessary. That same section of the datasheet also gives you the names of the MIcrochip Application Notes related to using crystals with a PIC. AN826, AN849, AN943, AN949. To get the applications note. Just Google them ... eg "Microchip AN949"
Below is a test program comfirmed to work for testing crystal operation o a 16F684. If working ok, the LED will blink at 1 Hz.
.
Thanks for the info and the program william. The clock circuit is surely ok, but i used 22pF caps. So as the oscilliator circuit (crystal+2 caps) are on a small part of a prototype pcb which is connected with jumper wires to pic's OSC1, OSC2 pins, you think that maybe these add up capacitance beyond maximum allowed? Maybe i should try with 10pF as you say then?
Glad you are getting it working.The expansion port needs stuff less than 2 inches away if I remember. There's a wait for screen refresh command somewhere so I guess you disable interrupts when you access ports.
No stan, i don't have to disable interrupts, amstrad works as usual.
First i have to learn what signals i need (and what levels should have) in order to recognize that amstrad calls an I/O port. Thankfully, it wasn't so hard thing to find:
http://www.cpcwiki.eu/index.php/Connector:Expansion_port
If you take a look above, you will easily find out that combining IORQ=0 and M1=1 defines exclusively that amstrad is calling an I/O port (that's how i get rid of interrupts which also have IORQ=0 signal, but M1=0).
This is the first step. But as the Gate Array 40010 chip inside amstrad (this is the "general management" chip which controls and synchronizing everything) makes frequent calls to internal I/O ports too (mostly to 6845 CRT Chip: http://www.cpcwiki.eu/index.php/Default_I/O_Port_Summary ), we need a way to define that only when a specific port is selected, pic will react.
This was a bit more "Tricky", as i had to know the port allocation of amstrad, which fortunately, was also provided from here: http://cpctech.cpc-live.com/docs/iopord.html
A bit of studying reveald that using only two more signals (2 address bits to be more precise) , i finally managed to recognize when amstrad makes an I/O call to a SPECIFIC port! ;-)
Last edit: ikonsgr74 2017-06-08
Sounds interesting. It's ages since I used one.I vaguely remember di was cancelled by hardware polling and erasing and redrawing graphics in a frame refresh was not as viable as a bbc micro.Before cpc 464 launch 2 guys I knew set up britannia software and got a white cpc464 with hard wired ula proto type same size as the 464 hanging off the back. The guys were selling rom boxes and having problems with the expansion pcb edge not being buffered. I used maxim or summat assembler on rom and it let you write bigger programs cos the assembler wasn't in ram.
Nostalgia,sigh.
ps pic programmers used to use the parallel printer port and needed accurate timing so maybe try using that directly, Just a thought
Last edit: stan cartwright 2017-06-08
I already did that, and worked perfect! The strobe and ready signals are the only signals provided with printer port (besides the data bits of course), but they were just enough to be able to manage communication with pic. Unfortunately amstrad's printer port, has 2 major "flaws":
First and most important, printer port is output only, you can't accept data from outside using printer port.
Secondly, data bus is 7bit, so you can't send a full byte at once, (actually you can, using software but this would be awfully slow -as you need to send half byte each time- and it requires special software on the other side too)
I'm a member of a retro computer fun club here in Greece, and we really enjoy "playing" with our beloved home micro's especially the old 8bit! ;-)