No changes between revisions
/Designs/Measuring_instruments/RMDS02D/SW/Readme.txt
0,0 → 1,9
The firmware should be flashed by bash script.
 
./flash.sh
 
The script downloads, compile and install the pk2cmd utility. After that firmware is flashed.
 
PIC microcontroler should be powered from programmer during this process.
 
 
/Designs/Measuring_instruments/RMDS02D/SW/flash.sh
0,0 → 1,6
#!/bin/bash
git clone https://github.com/jda/pk2cmd.git
cd pk2cmd
make linux
sudo make install
pk2cmd -PPIC16F887 -M -Y -W -F../main.hex
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/Designs/Measuring_instruments/RMDS02D/SW/main.hex
0,0 → 1,89
:1000000001308A00C2290000FF00030E8301A10015
:100010000A08A0008A010408A2007708A300780853
:10002000A4007908A5007A08A600831383120B1E8A
:100030001B288B1838288C308400001C21280C18B1
:100040003B288C308400801D27288C193E282208EC
:1000500084002308F7002408F8002508F900260882
:10006000FA0020088A00210E8300FF0E7F0E09008F
:100070008A110A12BA288A110A1292298A110A12BE
:100080004E2813087008930014168C118316141848
:100090004728F8018312141AF80A08008316941AE4
:1000A00059288312E9018316141D59288312E91770
:1000B000831683126908E90AEE006E087F3C031C70
:1000C0007D2814138C1D622813081416ED006E0B86
:1000D0006B286D08B4006E08023C031D7D28B4082F
:1000E000031D7728ED08031D77282F147D2837304E
:1000F0003407840083136D0880006E08803C031D64
:100100009B28B408031D8C282B08B0002C08B100D4
:100110002D08B2002E08B3003408043C031C9928B3
:1001200030303407840083130008EF00F0004120D2
:100130009B28F00141206E08813C031DA228310854
:10014000F00041206E08823C031DA9283208F0000F
:1001500041206E08833C031DB0283308F000412085
:100160006E08833C0318B628F00141208C118A11D7
:100170000A1227283608F1003508F0000F08FA00A7
:100180000E08F7000F087A02031DBE287708ED005D
:100190007A08EE00EF018316091083120910831606
:1001A0008910831289102814280883168700831267
:1001B000EF010718EF0A8316091083120914281497
:1001C0002808831687000030831207180130F700D3
:1001D0000310F70D7708EF04831609108312091036
:1001E000831689108312891428142808831687001F
:1001F0000030831207180130F700F70DF70DFC30BF
:10020000F7057708EF0483160910831209142814E0
:100210002808831687000030831207180130F70082
:10022000F70DF70DF70DF830F7057708EF04831693
:10023000861108308312860683160911831209116C
:1002400083160911831209158F018E01B601B501BC
:100250008316A301A2017108A1007008A000210863
:10026000A3002008A200A001A101A20DA30DA20DD0
:10027000A30DA20DA30DA20DA30DF030A205A801A0
:10028000A70183126E088316A60083126D088316D9
:10029000A500250DF700260DF800270DF900280D03
:1002A000FA00F70DF80DF90DFA0DF70DF80DF90D2F
:1002B000FA0DF70DF80DF90DFA0DF030F705770886
:1002C000A00778080318780FA10779080318790F99
:1002D000A2077A0803187A0FA3078312F801F9011D
:1002E000FA016F08831620078312AB0083162108DA
:1002F0008312AC0078080318780FAC078316220825
:100300008312AD0079080318790FAD07831623080F
:100310008312AE007A0803187A0FAE078B108A1189
:100320000A122728B50A0319B60A0C108A110A12F4
:1003300027286B308400831300080319AC2906308A
:10034000F800F701F70BA229F80BA1297B30F70081
:10035000F70BA829800B9F2908003708EB00013014
:10036000EA006A086B02031CC12937306A0784005F
:1003700083130008EC006C080C1EBC299900EA0AE3
:10038000B1290800840183131F30830583160317E6
:10039000871508300313990002309A00A6309800A0
:1003A000903083129800A8152808831687008312BE
:1003B0002816280883168700A2309300363083124F
:1003C0009400B401B601B501831603170908C039BA
:1003D000890003131F129F12003003178800831235
:1003E0008701880189010313A701FF30A800A90133
:1003F000AA012830B700B530B8006230B900063025
:10040000BA003130BB002030BC00BD01BE01BF01CD
:10041000C001C1013230C200C301C401C501803036
:10042000C6009630C7009830C800C901E030CA0045
:10043000C830CB001030CC00CD016430CE00CF01ED
:10044000D001D101D201D301D401D501D601D70108
:10045000D801D9017330DA00DB01DC01DD01C630DF
:10046000DE005130DF00E001E101E201E301E401DF
:10047000E501E601E701E8010330E900831603170F
:100480000908C039890003131F129F120030031797
:100490008800831203131F1083160108C739083818
:1004A000810009308312031785000F30F700031312
:1004B00081018130840083130008F03907388000FF
:1004C00064000008F739F719F03977048000073025
:1004D00090000030F80092000030831692008312E2
:1004E00003178701880189018316031397016400AC
:1004F00004308312EA00FA30EB009921EA0B7B2AE0
:100500006400AD21831601170C1483120B16831699
:100510008C15C03083128B04B001B101B201B3015C
:100520002F1064000430EA00FA30EB009921EA0B46
:10053000942A2F1C9D2AAD212F1083168611083076
:0805400083128606912A630074
:04400E00EA2CFF3F5A
:00000001FF
;PIC16F887
;CRC=24C8 CREATED="26-Oct-14 00:38"
/Designs/Measuring_instruments/RMDS02D/SW/src/main.c
0,0 → 1,203
// Atomic counter with I2C and RS232 output
 
// Usage conditions:
// 1. The first I2C or RS232 readout can be performed minimally 20 s after power up.
// 2. The I2C internal address 0 has to be read first.
// 3. An I2C readout can be performed at 15-th, 35-th and 55-th second of UTC.
//
// Counter gives 32 bit value:
// I2C register address 0 = LSB
// I2C register address 3 = MSB
 
#define ID "$Id: main.c 3741 2014-10-25 22:30:12Z kakl $"
#include "main.h"
#use i2c(SLAVE, Fast, sda=PIN_C4, scl=PIN_C3, force_hw, address=0xA2)
 
#include <string.h>
 
#define LED PIN_B3 // heartbeat indicator
#define SEL0 PIN_E0 // external counter division ratio
#define SEL1 PIN_E1 // external counter division ratio
#define MR PIN_E2 // external counter master reset
#define CLKI PIN_C0 // internal counter input
 
unsigned int32 count; // count per second
 
int1 fire_setup; // flag for sending setup to GPS
 
#define BUF_LEN 4
int8 buffer[BUF_LEN]; // I2C buffer
int8 address=0;
 
unsigned int16 of=0; // count of overflow
 
// 1x 100 us per 10 s UTC synchronised; 40 configuration bytes
char cmd[50]={40, 0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x80, 0x96, 0x98, 0x00, 0xE0, 0xC8, 0x10, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0xC6, 0x51};
 
// configure GPS
void setup_GPS()
{
int n;
int len;
len=cmd[0];
for (n=1;n<=len;n++) putc(cmd[n]);
}
 
#INT_SSP
void ssp_interupt ()
{
int8 incoming, state;
 
state = i2c_isr_state();
 
if(state < 0x80) //Master is sending data
{
incoming = i2c_read(); // Read byte
 
if(state == 1) //Second received byte is address of register
{
address = incoming;
}
 
if(state == 2) //Thid received byte are configuration data
{
if ((address==0)&&(incoming==0))
{
fire_setup = 1; // Write configuration to the GPS if configuration data length is 0
}
else
{
cmd[address] = incoming; // Store byte to configuration sentence
}
}
}
if(state == 0x80) //Master is requesting data
{
//i2c_read(); // Dummy read of I2C device address
if(address == 0) // Change buffer atomically at reading of the first byte
{
buffer[0]=make8(count,0);
buffer[1]=make8(count,1);
buffer[2]=make8(count,2);
buffer[3]=make8(count,3);
}
if(address <= BUF_LEN)
{
i2c_write(buffer[address]); // Prepare one byte to SSP buffer
}
else
{
i2c_write(0x00); // There is nothing to prepare, so zero
}
}
 
if(state == 0x81) //Master is requesting data
{
i2c_write(buffer[1]); // Prepare next byte to SSP buffer
}
if(state == 0x82) //Master is requesting data
{
i2c_write(buffer[2]); // Prepare next byte to SSP buffer
}
if(state == 0x83) //Master is requesting data
{
i2c_write(buffer[3]); // Prepare next byte to SSP buffer
}
 
if(state > 0x83) //Master is requesting data
{
i2c_write(0x00); // There is nothing to prepare, so zero
}
}
 
 
 
#int_EXT // Interrupt from 1PPS (RB0)
void EXT_isr(void)
{
unsigned int16 countH;
unsigned int8 countL;
int16 of2;
of2=of; // read overflow counter
countH=get_timer1(); // read internal counter
countL=0;
output_low(SEL0);
output_low(SEL1);
countL=input(CLKI); // read bit 0 of external counter
output_high(SEL0);
// output_low(SEL1);
countL|=input(CLKI)<<1; // read bit 1 of external counter
output_low(SEL0);
output_high(SEL1);
countL|=input(CLKI)<<2; // read bit 2 of external counter
output_high(SEL0);
// output_high(SEL1);
countL|=input(CLKI)<<3; // read bit 3 of external counter
 
output_toggle(LED); // heartbeat
output_low(MR); // External counter Master Reset
output_high(MR);
set_timer1(0); // Internal counter reset
of=0; // Overflow counter reset
count=((unsigned int32)of2<<20)+((unsigned int32)countH<<4)+(unsigned int32)countL; // concatenate
 
// printf("%010Lu\r\n", count);
}
 
#int_TIMER1 // Interrupf from overflow
void TIMER1_isr(void)
{
of++;
}
 
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
// setup_spi(SPI_SS_DISABLED); //must not be set if I2C are in use!
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_wdt(WDT_2304MS);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
 
restart_wdt();
delay_ms(1000);
restart_wdt();
// setup GPS
setup_GPS();
 
ext_int_edge( L_TO_H ); // set 1PPS active edge
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_EXT);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
buffer[0]=0x0; // Clear I2C output buffer
buffer[1]=0x0;
buffer[2]=0x0;
buffer[3]=0x0;
 
//printf("\r\ncvak...\r\n");
fire_setup = 0;
 
while(true)
{
restart_wdt();
delay_ms(1000);
if (fire_setup)
{
setup_GPS(); // Write configuration to the GPS
fire_setup = 0;
}
output_toggle(LED); // heartbeat
//printf("%X %X %X %X\r\n", buffer[0],buffer[1],buffer[2],buffer[3]);
//printf("%010Lu\r\n", count);
}
}
/Designs/Measuring_instruments/RMDS02D/SW/src/main.h
0,0 → 1,21
#include <16F887.h>
#device adc=8
 
#FUSES WDT //Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES PUT //Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES NOBROWNOUT //No brownout reset
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOWRT //Program memory not write protected
#FUSES BORV40 //Brownout reset at 4.0V
 
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)